class Thrift::HTTPClientTransport

Public Class Methods

new(url, opts = {}) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
30 def initialize(url, opts = {})
31   @url = URI url
32   @headers = {'Content-Type' => 'application/x-thrift'}
33   @outbuf = Bytes.empty_byte_buffer
34   @ssl_verify_mode = opts.fetch(:ssl_verify_mode, OpenSSL::SSL::VERIFY_PEER)
35 end

Public Instance Methods

add_headers(headers) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
41 def add_headers(headers)
42   @headers = @headers.merge(headers)
43 end
flush() click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
45 def flush
46   http = Net::HTTP.new @url.host, @url.port
47   http.use_ssl = @url.scheme == 'https'
48   http.verify_mode = @ssl_verify_mode if @url.scheme == 'https'
49   resp = http.post(@url.request_uri, @outbuf, @headers)
50   raise TransportException.new(TransportException::UNKNOWN, "#{self.class.name} Could not connect to #{@url}, HTTP status code #{resp.code.to_i}") unless (200..299).include?(resp.code.to_i)
51 
52   data = resp.body
53   data = Bytes.force_binary_encoding(data)
54   @inbuf = StringIO.new data
55 ensure
56   @outbuf = Bytes.empty_byte_buffer
57 end
open?() click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
37 def open?; true end
read(sz) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
38 def read(sz); @inbuf.read sz end
to_s() click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
59 def to_s
60   "@{self.url}"
61 end
write(buf) click to toggle source
   # File lib/thrift/transport/http_client_transport.rb
39 def write(buf); @outbuf << Bytes.force_binary_encoding(buf) end