Class: Steppe::Endpoint::HeaderValidator
- Inherits:
-
Object
- Object
- Steppe::Endpoint::HeaderValidator
- Defined in:
- lib/steppe/endpoint.rb
Overview
Note:
HTTP header names in Rack env use the format ‘HTTP_*’ (e.g., ‘HTTP_AUTHORIZATION’)
Note:
Security schemes often use this to validate required headers (e.g., Authorization)
Internal step that validates HTTP headers against a schema. Validates headers from the Rack env and merges validated values back into the env. Returns 422 Unprocessable Entity if validation fails.
Instance Attribute Summary collapse
-
#header_schema ⇒ Object
readonly
Returns the value of attribute header_schema.
Instance Method Summary collapse
-
#call(conn) ⇒ Result
Validates headers from the request environment.
-
#initialize(header_schema) ⇒ HeaderValidator
constructor
A new instance of HeaderValidator.
Constructor Details
#initialize(header_schema) ⇒ HeaderValidator
Returns a new instance of HeaderValidator.
107 108 109 |
# File 'lib/steppe/endpoint.rb', line 107 def initialize(header_schema) @header_schema = header_schema.is_a?(Hash) ? Types::Hash[header_schema] : header_schema end |
Instance Attribute Details
#header_schema ⇒ Object (readonly)
Returns the value of attribute header_schema.
104 105 106 |
# File 'lib/steppe/endpoint.rb', line 104 def header_schema @header_schema end |
Instance Method Details
#call(conn) ⇒ Result
Validates headers from the request environment.
115 116 117 118 119 120 121 |
# File 'lib/steppe/endpoint.rb', line 115 def call(conn) result = header_schema.resolve(conn.request.env) conn.request.env.merge!(result.value) return conn.respond_with(422).invalid(errors: { headers: result.errors }) unless result.valid? conn.valid end |