class Thrift::HTTPClientTransport

Constants

DEFAULT_HEADERS

Public Class Methods

new(url, opts = {}) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
31 def initialize(url, opts = {})
32   @url = URI url
33   @headers = DEFAULT_HEADERS.merge(opts.fetch(:headers, {}))
34   @outbuf = Bytes.empty_byte_buffer
35   @ssl_verify_mode = opts.fetch(:ssl_verify_mode, OpenSSL::SSL::VERIFY_PEER)
36   @error_logger = opts[:error_logger]
37   @retries = opts.fetch(:retries, 1)
38   @open_timeout = opts[:open_timeout]
39   @read_timeout = opts[:read_timeout]
40 end

Public Instance Methods

flush() click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
54 def flush
55   tries ||= @retries
56   resp = http_client.post(@url.request_uri, @outbuf.dup, @headers)
57   resp.value
58   @inbuf = StringIO.new Bytes.force_binary_encoding(resp.body)
59 rescue => e
60   retry if (tries -= 1) > 0
61   raise TransportException.new(TransportException::UNKNOWN, e.to_s)
62 ensure
63   @outbuf = Bytes.empty_byte_buffer
64 end
open?() click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
42 def open?; true end
read(sz) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
44 def read(sz)
45   res = @inbuf.read(sz)
46 
47   raise TransportException.new(TransportException::END_OF_FILE) if res.nil?
48 
49   res
50 end
write(buf) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
52 def write(buf); @outbuf << Bytes.force_binary_encoding(buf) end

Private Instance Methods

http_client() click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
68 def http_client
69   http = Net::HTTP.new @url.host, @url.port
70   http.use_ssl = @url.scheme == 'https'
71   http.open_timeout = @open_timeout if @open_timeout
72   http.read_timeout = @read_timeout if @read_timeout
73   http.verify_mode = @ssl_verify_mode if @url.scheme == 'https'
74 
75   http
76 end