LoginSignup
0
0

More than 1 year has passed since last update.

Railsのレスポンスに任意のHTTPヘッダを追加するRackミドルウェア

Posted at
config/initializers/additional_http_headers.rb
class AdditionalHTTPHeaders
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, body = @app.call(env)
    additional_headers.each{|k, v| headers[k] = v }
    [status, headers, body]
  end

  private
    def additional_headers
      {
        'x-foo' => 'bar',
      }
    end
end

Rails.application.config.middleware.insert_before(
  ActionDispatch::Cookies, AdditionalHTTPHeaders
)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0