Class: Thrift::HTTPClientTransport
- Inherits:
-
BaseTransport
- Object
- BaseTransport
- Thrift::HTTPClientTransport
- Defined in:
- lib/thrift/transport/http_client_transport.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/x-thrift' }.freeze
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(url, opts = {}) ⇒ HTTPClientTransport
constructor
A new instance of HTTPClientTransport.
- #open? ⇒ Boolean
- #read(sz) ⇒ Object
- #write(buf) ⇒ Object
Methods inherited from BaseTransport
#close, #open, #read_all, #read_byte, #read_into_buffer, #set_context
Constructor Details
#initialize(url, opts = {}) ⇒ HTTPClientTransport
Returns a new instance of HTTPClientTransport.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/thrift/transport/http_client_transport.rb', line 31 def initialize(url, opts = {}) @url = URI url @headers = DEFAULT_HEADERS.merge(opts.fetch(:headers, {})) @outbuf = Bytes.empty_byte_buffer @ssl_verify_mode = opts.fetch(:ssl_verify_mode, OpenSSL::SSL::VERIFY_PEER) @error_logger = opts[:error_logger] @retries = opts.fetch(:retries, 1) @open_timeout = opts[:open_timeout] @read_timeout = opts[:read_timeout] end |
Instance Method Details
#flush ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/thrift/transport/http_client_transport.rb', line 54 def flush tries ||= @retries resp = http_client.post(@url.request_uri, @outbuf.dup, @headers) resp.value @inbuf = StringIO.new Bytes.force_binary_encoding(resp.body) rescue => e retry if (tries -= 1) > 0 raise TransportException.new(TransportException::UNKNOWN, e.to_s) ensure @outbuf = Bytes.empty_byte_buffer end |
#open? ⇒ Boolean
42 |
# File 'lib/thrift/transport/http_client_transport.rb', line 42 def open?; true end |
#read(sz) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/thrift/transport/http_client_transport.rb', line 44 def read(sz) res = @inbuf.read(sz) raise TransportException.new(TransportException::END_OF_FILE) if res.nil? res end |
#write(buf) ⇒ Object
52 |
# File 'lib/thrift/transport/http_client_transport.rb', line 52 def write(buf); @outbuf << Bytes.force_binary_encoding(buf) end |