Class: Hephaestus::Middleware::MalformedRequest

Inherits:
Object
  • Object
show all
Includes:
ActionController::HttpAuthentication::Basic
Defined in:
lib/hephaestus/middleware/malformed_request.rb

Overview

There is no valid reason for a request to contain a malformed string so just return HTTP 400 (Bad Request) if we receive one

Constant Summary collapse

NULL_BYTE_REGEX =
Regexp.new(Regexp.escape("\u0000")).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ MalformedRequest

Returns a new instance of MalformedRequest.



15
16
17
# File 'lib/hephaestus/middleware/malformed_request.rb', line 15

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



13
14
15
# File 'lib/hephaestus/middleware/malformed_request.rb', line 13

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
# File 'lib/hephaestus/middleware/malformed_request.rb', line 19

def call(env)
  return [Hephaestus::HTTP::BAD_REQUEST_I, { "Content-Type" => "text/plain" }, [Hephaestus::HTTP::BAD_REQUEST]] if request_contains_malformed_string?(env)

  app.call(env)
end