Class: Thrift::HTTPClientTransport
Instance Method Summary
collapse
#close, #open, #read_all, #read_byte, #read_into_buffer
Constructor Details
Returns a new instance of HTTPClientTransport.
30
31
32
33
34
35
|
# File 'lib/thrift/transport/http_client_transport.rb', line 30
def initialize(url, opts = {})
@url = URI url
@headers = {'Content-Type' => 'application/x-thrift'}
@outbuf = Bytes.empty_byte_buffer
@ssl_verify_mode = opts.fetch(:ssl_verify_mode, OpenSSL::SSL::VERIFY_PEER)
end
|
Instance Method Details
41
42
43
|
# File 'lib/thrift/transport/http_client_transport.rb', line 41
def ()
@headers = @headers.merge()
end
|
#flush ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/thrift/transport/http_client_transport.rb', line 45
def flush
http = Net::HTTP.new @url.host, @url.port
http.use_ssl = @url.scheme == 'https'
http.verify_mode = @ssl_verify_mode if @url.scheme == 'https'
resp = http.post(@url.request_uri, @outbuf, @headers)
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)
data = resp.body
data = Bytes.force_binary_encoding(data)
@inbuf = StringIO.new data
ensure
@outbuf = Bytes.empty_byte_buffer
end
|
#open? ⇒ Boolean
37
|
# File 'lib/thrift/transport/http_client_transport.rb', line 37
def open?; true end
|
#read(sz) ⇒ Object
38
|
# File 'lib/thrift/transport/http_client_transport.rb', line 38
def read(sz); @inbuf.read sz end
|
#to_s ⇒ Object
59
60
61
|
# File 'lib/thrift/transport/http_client_transport.rb', line 59
def to_s
"@{self.url}"
end
|
#write(buf) ⇒ Object
39
|
# File 'lib/thrift/transport/http_client_transport.rb', line 39
def write(buf); @outbuf << Bytes.force_binary_encoding(buf) end
|