Class: FakeAWS::S3::Request

Inherits:
Object
  • Object
show all
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

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

#bucketObject



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

#contentObject



22
23
24
# File 'lib/fake_aws/s3/request.rb', line 22

def content
  @env["rack.input"].read
end

#content_typeObject



18
19
20
# File 'lib/fake_aws/s3/request.rb', line 18

def content_type
  @env["CONTENT_TYPE"]
end

#has_key?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/fake_aws/s3/request.rb', line 55

def has_key?
  key != "/"
end

#http_headersObject



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

#keyObject



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

#methodObject



14
15
16
# File 'lib/fake_aws/s3/request.rb', line 14

def method
  @env["REQUEST_METHOD"]
end