Class: HttpMonkey::Middlewares::DefaultHeaders
- Inherits:
-
Object
- Object
- HttpMonkey::Middlewares::DefaultHeaders
- Defined in:
- lib/http_monkey/middlewares/default_headers.rb
Overview
Allow to set default HTTP headers to all requests
Examples
use HttpMonkey::Middlewares::DefaultHeaders, {"Content-Type" => "text/html",
"X-Custom" => "custom"}
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, headers = {}) ⇒ DefaultHeaders
constructor
A new instance of DefaultHeaders.
Constructor Details
#initialize(app, headers = {}) ⇒ DefaultHeaders
Returns a new instance of DefaultHeaders.
11 12 13 14 |
# File 'lib/http_monkey/middlewares/default_headers.rb', line 11 def initialize(app, headers = {}) @app = app @headers = headers end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/http_monkey/middlewares/default_headers.rb', line 16 def call(env) @headers.each do |header, value| http_header = "HTTP_#{header.to_s.upcase.gsub("-", "_")}" env[http_header] = value unless env.key?(http_header) end @app.call(env) end |