Class: Thrift::HTTPClientTransport

Inherits:
BaseTransport show all
Defined in:
lib/thrift/transport/http_client_transport.rb

Instance Method Summary collapse

Methods inherited from BaseTransport

#close, #open, #read_all, #read_byte, #read_into_buffer

Constructor Details

#initialize(url, proxy_addr = nil, proxy_port = nil) ⇒ HTTPClientTransport

Returns a new instance of HTTPClientTransport.



29
30
31
32
33
34
35
# File 'lib/thrift/transport/http_client_transport.rb', line 29

def initialize(url, proxy_addr = nil, proxy_port = nil)
  @url = URI url
  @headers = {'Content-Type' => 'application/x-thrift'}
  @outbuf = ""
  @proxy_addr = proxy_addr
  @proxy_port = proxy_port
end

Instance Method Details

#add_headers(headers) ⇒ Object



41
42
43
# File 'lib/thrift/transport/http_client_transport.rb', line 41

def add_headers(headers)
  @headers = @headers.merge(headers)
end

#flushObject



45
46
47
48
49
50
51
# File 'lib/thrift/transport/http_client_transport.rb', line 45

def flush
  http = Net::HTTP.new @url.host, @url.port, @proxy_addr, @proxy_port
  http.use_ssl = @url.scheme == "https"
  resp = http.post(@url.request_uri, @outbuf, @headers)
  @inbuf = StringIO.new resp.body
  @outbuf = ""
end

#open?Boolean

Returns:

  • (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

#write(buf) ⇒ Object



39
# File 'lib/thrift/transport/http_client_transport.rb', line 39

def write(buf); @outbuf << buf end