Class: Bucketrb::App

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

Constant Summary collapse

XML_CONTENT_TYPE =
"application/xml"
DEFAULT_CONTENT_TYPE =
"application/octet-stream"

Instance Method Summary collapse

Constructor Details

#initialize(store:) ⇒ App

Returns a new instance of App.



16
17
18
# File 'lib/bucketrb/app.rb', line 16

def initialize(store:)
  @store = store
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bucketrb/app.rb', line 20

def call(env)
  request = Rack::Request.new(env)
  return options_response if request.options?

  bucket, key = path_parts(request.path_info)

  if bucket.nil?
    return root_request(request)
  end

  dispatch(request, bucket, key)
rescue Bucketrb::BucketNotFoundError => error
  error_response("NoSuchBucket", error.message, 404, head: env["REQUEST_METHOD"] == "HEAD")
rescue Bucketrb::ObjectNotFoundError => error
  error_response("NoSuchKey", error.message, 404, head: env["REQUEST_METHOD"] == "HEAD")
rescue Bucketrb::InvalidBucketNameError, Bucketrb::InvalidObjectKeyError, ArgumentError => error
  error_response("InvalidArgument", error.message, 400, head: env["REQUEST_METHOD"] == "HEAD")
rescue StandardError => error
  warn "#{error.class}: #{error.message}"
  warn error.backtrace.join("\n") if ENV["BUCKETRB_DEBUG"]
  error_response("InternalError", error.message, 500, head: env["REQUEST_METHOD"] == "HEAD")
end