Class: S3Proxy::App

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_proxy/app.rb

Defined Under Namespace

Modules: Errors

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ App

Returns a new instance of App.



6
7
8
# File 'lib/s3_proxy/app.rb', line 6

def initialize(options={})
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/s3_proxy/app.rb', line 10

def call(env)
  return Errors.method_not_allowed unless env['REQUEST_METHOD'] == 'GET'
  return Errors.not_found if env['PATH_INFO'].empty?

  _, bucket, key = env['PATH_INFO'].split('/', 3)
  path = {bucket: bucket, key: key}

  head = s3.head_object(path)
  return Errors.not_found unless head

  if env['rack.hijack?']
    hijack env, path, head
  else
    gentle env, path, head
  end

rescue Aws::S3::Errors::NoSuchKey
  return Errors.not_found
end