Class: BigSession::FaradayBigSession
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- BigSession::FaradayBigSession
- Defined in:
- lib/big_session/faraday.rb
Overview
This middleware will add BigSession header to request_headers of outgoing connections done by Faraday
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, header_secret = nil) ⇒ FaradayBigSession
constructor
A new instance of FaradayBigSession.
Constructor Details
#initialize(app, header_secret = nil) ⇒ FaradayBigSession
Returns a new instance of FaradayBigSession.
16 17 18 19 |
# File 'lib/big_session/faraday.rb', line 16 def initialize(app, header_secret = nil) @app = app @header_secret = header_secret end |
Class Method Details
.activate ⇒ Object
11 12 13 |
# File 'lib/big_session/faraday.rb', line 11 def activate ::Faraday::Middleware.register_middleware big_session: ::BigSession::FaradayBigSession end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/big_session/faraday.rb', line 21 def call(env) if SessionId.current headers = { ::BigSession::BIG_SESSION_HEADER_NAME => SessionId.current, } if @header_secret sig = OpenSSL::HMAC.hexdigest('sha256', @header_secret, SessionId.current) headers[::BigSession::BIG_SESSION_SIGNATURE_HEADER_NAME] = sig end env[:request_headers].merge!(headers) end @app.call(env) end |