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.



101
102
103
# File 'lib/webhookdb/service/middleware.rb', line 101

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



105
106
107
108
109
110
# File 'lib/webhookdb/service/middleware.rb', line 105

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