Class: Rack::PactBroker::InvalidUriProtection

Inherits:
Object
  • Object
show all
Includes:
PactBroker::Messages
Defined in:
lib/rack/pact_broker/invalid_uri_protection.rb

Constant Summary collapse

CONSECUTIVE_SLASH =
/\/{2,}/

Instance Method Summary collapse

Methods included from PactBroker::Messages

#message, #pluralize, #validation_message, #validation_message_at_index

Constructor Details

#initialize(app) ⇒ InvalidUriProtection

Returns a new instance of InvalidUriProtection.



17
18
19
# File 'lib/rack/pact_broker/invalid_uri_protection.rb', line 17

def initialize app
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/pact_broker/invalid_uri_protection.rb', line 21

def call env
  if (uri = valid_uri?(env))
    if (error_message = validate(uri))
      [422, headers, [body(env, error_message, "Unprocessable", "invalid-request-parameter-value", 422)]]
    else
      app.call(env)
    end
  else
    [404, headers, [body(env, "Empty path component found", "Not Found", "not-found", 404)]]
  end
end