Class: Webhookdb::Service::Middleware::CopyCookieToExplicitHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/service/middleware.rb

Overview

In browser environments, they can’t access the Cookie header for API requests, and it doesn’t always get the automatic binding behavior we want (for example fetches made from WASM). So copy it into something we can access. This must be before the Rack session middleware.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CopyCookieToExplicitHeader

Returns a new instance of CopyCookieToExplicitHeader.



92
93
94
# File 'lib/webhookdb/service/middleware.rb', line 92

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



96
97
98
99
100
101
# File 'lib/webhookdb/service/middleware.rb', line 96

def call(env)
  env["HTTP_COOKIE"] = env[Webhookdb::Service::AUTH_TOKEN_HTTP] if env[Webhookdb::Service::AUTH_TOKEN_HTTP]
  status, headers, body = @app.call(env)
  headers[Webhookdb::Service::AUTH_TOKEN_HEADER] = headers["Set-Cookie"] if headers["Set-Cookie"]
  return status, headers, body
end