class Thrift::FaradayTransport
Faraday HTTP-transport for Thrift
Constants
- BASE_HEADERS
Base headers for response
- VERSION
Gem trhfit-faraday_transport version
Attributes
faraday_connection[R]
@return [Faraday::Connection] attribute faraday_connection
Public Class Methods
new(faraday_connection)
click to toggle source
Initialize new Faraday transport
@param faraday_connection
[Faraday::Connection]
@return [Thrift::FaradayTransport]
# File lib/thrift/faraday_transport.rb, line 42 def initialize(faraday_connection) @faraday_connection = faraday_connection flush_out_buffer end
Public Instance Methods
flush()
click to toggle source
Perform HTTP request. Implement Thrift::BaseTransport#flush
@raise [UnexpectedHTTPCode] when HTTP server respond with not 200 status @raise [FaradayException] on Faraday client exception
# File lib/thrift/faraday_transport.rb, line 69 def flush response = perform_request raise UnexpectedHTTPCode, response.status if response.status != 200 body = Bytes.force_binary_encoding(response.body) @in_buffer = StringIO.new(body) ensure flush_out_buffer end
open?()
click to toggle source
# File lib/thrift/faraday_transport.rb, line 47 def open? true end
read(size)
click to toggle source
Implement Thrift::BaseTransport#read
@param size [Integer]
# File lib/thrift/faraday_transport.rb, line 61 def read(size) @in_buffer.read(size) end
write(data)
click to toggle source
Implement Thrift::BaseTransport#write
@param data [String]
# File lib/thrift/faraday_transport.rb, line 54 def write(data) @out_buffer << data end
Private Instance Methods
flush_out_buffer()
click to toggle source
# File lib/thrift/faraday_transport.rb, line 80 def flush_out_buffer @out_buffer = Bytes.empty_byte_buffer end
perform_request()
click to toggle source
# File lib/thrift/faraday_transport.rb, line 84 def perform_request @faraday_connection.post do |request| request.body = @out_buffer request.headers.merge!(BASE_HEADERS) end rescue Faraday::ClientError => e raise FaradayException, e end