Class: UberS3::Connection::NetHttp

Inherits:
Adapter
  • Object
show all
Defined in:
lib/uber-s3/connection/net_http.rb

Instance Attribute Summary

Attributes inherited from Adapter

#access_key, #client, #defaults, #persistent, #secret_access_key

Instance Method Summary collapse

Methods inherited from Adapter

#initialize

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
# 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
  
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  
  req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize)
  req = req_klass.new(uri.to_s, headers)
  
  r = http.request(req, body)
  
  # 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