Sha256: 1b672ae673c6bae1d24f29ce9de95fc8191fd3e539c884285d9bf332f627fb73
Contents?: true
Size: 843 Bytes
Versions: 3
Compression:
Stored size: 843 Bytes
Contents
require 'active_support' require 'active_support/core_ext' # Rack middleware to add arbitrary HTTP headers to responses. class AddHttpHeader # Initialize with the headers to add. Headers should be a hash. The headers are added after the request # is processed. The values of the headers hash can be Proc objects in which case they are called with the # request environment, response status, and response headers at runtime. In this way, you can add dynamic # values as headers. def initialize (app, headers) @app = app @headers = headers end def call (env) status, headers, body = @app.call(env) @headers.each_pair do |name, value| value = value.call(env, status, headers) if value.is_a?(Proc) headers[name.to_s] = value.to_s unless value.blank? end return [status, headers, body] end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
add_http_header-1.0.4 | lib/add_http_header.rb |
add_http_header-1.0.3 | lib/add_http_header.rb |
add_http_header-1.0.2 | lib/add_http_header.rb |