Class: FakeAWS::S3::Request
- Inherits:
-
Object
- Object
- FakeAWS::S3::Request
- Defined in:
- lib/fake_aws/s3/request.rb
Overview
Extract the bucket and key from the various different styles of S3 request.
See docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
Instance Method Summary collapse
- #bucket ⇒ Object
- #content ⇒ Object
- #content_type ⇒ Object
- #has_key? ⇒ Boolean
- #http_headers ⇒ Object
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
- #key ⇒ Object
- #method ⇒ Object
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 |
# File 'lib/fake_aws/s3/request.rb', line 8 def initialize(env) @env = env @server_name = env["SERVER_NAME"] @path_info = env["PATH_INFO"] end |
Instance Method Details
#bucket ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fake_aws/s3/request.rb', line 31 def bucket @bucket ||= case request_style when :path path_components.first when :virtual_hosted server_name_components[0..-4].join(".") when :cname @server_name else raise "Uh oh" end end |
#content ⇒ Object
22 23 24 |
# File 'lib/fake_aws/s3/request.rb', line 22 def content @env["rack.input"].read end |
#content_type ⇒ Object
18 19 20 |
# File 'lib/fake_aws/s3/request.rb', line 18 def content_type @env["CONTENT_TYPE"] end |
#has_key? ⇒ Boolean
55 56 57 |
# File 'lib/fake_aws/s3/request.rb', line 55 def has_key? key != "/" end |
#http_headers ⇒ Object
26 27 28 29 |
# File 'lib/fake_aws/s3/request.rb', line 26 def http_headers http_headers = env_headers.map {|key, value| [header_key_for_env_key(key), value] } Hash[http_headers] end |
#key ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fake_aws/s3/request.rb', line 44 def key @key ||= "/" + case request_style when :path path_components.drop(1).join("/") when :virtual_hosted, :cname path_components.join("/") else raise "Uh oh" end end |
#method ⇒ Object
14 15 16 |
# File 'lib/fake_aws/s3/request.rb', line 14 def method @env["REQUEST_METHOD"] end |