Class: Stark::HTTP::ClientTransport
- Inherits:
-
Thrift::BaseTransport
- Object
- Thrift::BaseTransport
- Stark::HTTP::ClientTransport
- Defined in:
- lib/stark/http.rb
Constant Summary collapse
- RETRY_ATTEMPTS =
10
Instance Method Summary collapse
- #add_headers(headers) ⇒ Object
- #flush ⇒ Object
-
#initialize(url) ⇒ ClientTransport
constructor
A new instance of ClientTransport.
- #open? ⇒ Boolean
- #read(sz) ⇒ Object
- #write(buf) ⇒ Object
Constructor Details
#initialize(url) ⇒ ClientTransport
Returns a new instance of ClientTransport.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/stark/http.rb', line 11 def initialize(url) @url = URI url @headers = {'Content-Type' => 'application/x-thrift', 'User-Agent' => Stark::HTTP::HTTP_USER_AGENT } @outbuf = "" @http = Net::HTTP.new @url.host, @url.port @http.use_ssl = @url.scheme == "https" if $DEBUG @http.set_debug_output $stderr end end |
Instance Method Details
#add_headers(headers) ⇒ Object
28 29 30 |
# File 'lib/stark/http.rb', line 28 def add_headers(headers) @headers = @headers.merge(headers) end |
#flush ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/stark/http.rb', line 34 def flush attempts = 0 @http.start unless @http.started? begin resp = @http.post(@url.request_uri, @outbuf, @headers) attempts = 0 rescue StandardError => e @http.finish raise e if attempts > RETRY_ATTEMPTS attempts += 1 @http.start retry end @inbuf = StringIO.new resp.body @outbuf = "" end |
#open? ⇒ Boolean
24 |
# File 'lib/stark/http.rb', line 24 def open?; true end |
#read(sz) ⇒ Object
25 |
# File 'lib/stark/http.rb', line 25 def read(sz); @inbuf.read sz end |
#write(buf) ⇒ Object
26 |
# File 'lib/stark/http.rb', line 26 def write(buf); @outbuf << buf end |