Class: UberS3::Connection::NetHttp
- Defined in:
- lib/uber-s3/connection/net_http.rb
Instance Attribute Summary
Attributes inherited from Adapter
#access_key, #defaults, #http, #s3, #secret_access_key, #uri
Instance Method Summary collapse
Methods inherited from Adapter
Constructor Details
This class inherits a constructor from UberS3::Connection::Adapter
Instance Method Details
#request(verb, url, headers = {}, body = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/uber-s3/connection/net_http.rb', line 6 def request(verb, url, headers={}, body=nil) if verb == :get # Support fetching compressed data headers['Accept-Encoding'] = 'gzip, deflate' end self.uri = URI.parse(url) # Init and open a HTTP connection self.http ||= Net::HTTP.new(uri.host, uri.port) if !http.started? || !http.active? http.start if Socket.const_defined?(:TCP_NODELAY) socket = http.instance_variable_get(:@socket) socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) end end req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize) req = req_klass.new(uri.to_s, headers) req.body = body if !body.nil? && !body.empty? # Make HTTP request r = http.request(req) # $stderr.puts "active? " + http.active?.to_s # Auto-decode any gzipped objects if verb == :get && r.header['Content-Encoding'] == 'gzip' gz = Zlib::GzipReader.new(StringIO.new(r.body)) response_body = gz.read else response_body = r.body end UberS3::Response.new({ :status => r.code.to_i, :header => r.header.to_hash, :body => response_body, :raw => r }) end |