class Thrift::HTTPClientTransport
Public Class Methods
new(url, proxy_addr = nil, proxy_port = nil)
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 29 def initialize(url, proxy_addr = nil, proxy_port = nil) @url = URI url @headers = default_headers @ssl_attributes = default_ssl_attributes @outbuf = Bytes.empty_byte_buffer @proxy_addr = proxy_addr @proxy_port = proxy_port end
Public Instance Methods
add_headers(headers)
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 42 def add_headers(headers) @headers = @headers.merge(headers) end
add_ssl_attributes(attributes)
click to toggle source
Add ssl attributes for underlying Net::HTTP instance.
attributes - Hash of Symbols to values where keys correspond to ssl
attributes of Net::HTTP like ca_file, verify_mode, etc.
# File lib/thrift/transport/http_client_transport.rb, line 50 def add_ssl_attributes(attributes) @ssl_attributes = @ssl_attributes.merge(attributes) end
flush()
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 54 def flush http = Net::HTTP.new @url.host, @url.port, @proxy_addr, @proxy_port apply_ssl_attributes(http) if @url.scheme == "https" resp = http.post(@url.request_uri, @outbuf, @headers) if 'application/x-thrift'.downcase != resp.content_type.to_s.downcase raise TransportException.new(TransportException::UNKNOWN, "Unexpected response content type: '#{resp.content_type}'") end data = resp.body data = Bytes.force_binary_encoding(data) @inbuf = StringIO.new data @outbuf = Bytes.empty_byte_buffer end
open?()
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 38 def open?; true end
read(sz)
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 39 def read(sz); @inbuf.read sz end
write(buf)
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 40 def write(buf); @outbuf << Bytes.force_binary_encoding(buf) end
Private Instance Methods
apply_ssl_attributes(http)
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 81 def apply_ssl_attributes(http) @ssl_attributes.each do |k, v| http.__send__("#{k}=", v) end end
default_headers()
click to toggle source
# File lib/thrift.rb, line 64 def default_headers gem_version = Gem.loaded_specs['evernote-thrift'].version.to_s {'Content-Type' => 'application/x-thrift', 'User-Agent' => "evernote-thrift gem / #{gem_version}; Ruby / #{RUBY_VERSION};"} rescue original_default_headers end
Also aliased as: original_default_headers
default_ssl_attributes()
click to toggle source
# File lib/thrift/transport/http_client_transport.rb, line 76 def default_ssl_attributes {:use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_PEER} end