Class: Rubytus::Middlewares::TusBarrier

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware, Constants
Defined in:
lib/rubytus/middlewares/tus_barrier.rb

Constant Summary

Constants included from Constants

Constants::BASE_PATH_REGEX, Constants::COMMON_HEADERS, Constants::DEFAULT_BASE_PATH, Constants::DEFAULT_DATA_DIR, Constants::DEFAULT_MAX_SIZE, Constants::DEFAULT_STORAGE, Constants::ENV_BASE_PATH, Constants::ENV_DATA_DIR, Constants::ENV_MAX_SIZE, Constants::ENV_STORAGE, Constants::RESOURCE_UID_REGEX, Constants::RESUMABLE_CONTENT_TYPE, Constants::STATUS_BAD_REQUEST, Constants::STATUS_CREATED, Constants::STATUS_FORBIDDEN, Constants::STATUS_INTERNAL_ERROR, Constants::STATUS_NOT_ALLOWED, Constants::STATUS_NOT_FOUND, Constants::STATUS_OK

Instance Method Summary collapse

Instance Method Details

#post_process(env, status, headers, body) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubytus/middlewares/tus_barrier.rb', line 7

def post_process(env, status, headers, body)
  request = Rubytus::Request.new(env)

  if request.collection?
    unless request.options? || request.post?
      status = STATUS_NOT_ALLOWED
      body   = "#{request.request_method} used against file creation url. Only POST is allowed."
      headers['Allow'] = 'POST'
    end
  end

  if request.resource?
    unless request.options? || request.head? || request.patch? || request.get?
      status  = STATUS_NOT_ALLOWED
      allowed = 'HEAD,PATCH'
      body    = "#{request.request_method} used against file creation url. Allowed: #{allowed}"
      headers['Allow'] = allowed
    end
  end

  if request.unknown?
    status = STATUS_NOT_FOUND
    body   = "Unknown url: #{request.path_info} - does not match file pattern"
  end

  [status, headers, body]
end