Class: AWSRaw::S3::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/awsraw/s3/request.rb

Overview

Note that we use path style (rather than virtual hosted style) requests. This is because virtual hosted requests only support lower case bucket names.

See docs.amazonwebservices.com/AmazonS3/latest/dev/VirtualHosting.html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, signer) ⇒ Request

Returns a new instance of Request.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/awsraw/s3/request.rb', line 16

def initialize(params, signer)
  @method  = params[:method]
  @bucket  = params[:bucket]
  @region  = params[:region]
  @key     = params[:key]
  @query   = params[:query]
  @headers = params[:headers] || {}
  @content = params[:content]

  raise "Content without Content-Type" if !@content.nil? && @headers["Content-Type"].nil?

  headers["Content-MD5"]   = content_md5 unless content.nil?
  headers["Date"]          = Time.now.rfc2822
  headers["Authorization"] = signer.signature(self)
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



33
34
35
# File 'lib/awsraw/s3/request.rb', line 33

def bucket
  @bucket
end

#contentObject (readonly)

Returns the value of attribute content.



37
38
39
# File 'lib/awsraw/s3/request.rb', line 37

def content
  @content
end

#headersObject (readonly)

Returns the value of attribute headers.



36
37
38
# File 'lib/awsraw/s3/request.rb', line 36

def headers
  @headers
end

#keyObject (readonly)

Returns the value of attribute key.



34
35
36
# File 'lib/awsraw/s3/request.rb', line 34

def key
  @key
end

#methodObject (readonly)

Returns the value of attribute method.



32
33
34
# File 'lib/awsraw/s3/request.rb', line 32

def method
  @method
end

#queryObject (readonly)

Returns the value of attribute query.



35
36
37
# File 'lib/awsraw/s3/request.rb', line 35

def query
  @query
end

Instance Method Details

#content_md5Object



59
60
61
# File 'lib/awsraw/s3/request.rb', line 59

def content_md5
  @content_md5 ||= Base64.encode64(MD5Digester.new(content).digest).strip
end

#hostObject



39
40
41
42
43
44
45
# File 'lib/awsraw/s3/request.rb', line 39

def host
  if @region && @region != US_STANDARD
    "s3-#{@region}.amazonaws.com"
  else
    "s3.amazonaws.com"
  end
end

#pathObject



47
48
49
# File 'lib/awsraw/s3/request.rb', line 47

def path
  @path ||= URI.escape("/#{bucket}#{key}")
end

#uriObject



51
52
53
54
55
56
57
# File 'lib/awsraw/s3/request.rb', line 51

def uri
  @uri ||= URI::HTTP.build(
    :host  => host,
    :path  => path,
    :query => query
  )
end