Class: MCPClient::HttpTransportBase::CacheSupport::AuthorizationRecorder
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- MCPClient::HttpTransportBase::CacheSupport::AuthorizationRecorder
- Defined in:
- lib/mcp_client/http_transport_base/cache_support.rb
Overview
Innermost middleware on the JSON-RPC connection: it records the
Authorization a request carries once every host middleware
(faraday_config) has run, right before the adapter sends it, and the
moment the response came back, before any host on_complete had it.
A request that then times out or fails to connect still has a known
context, so the stale copy of that context may be served.
Instance Method Summary collapse
-
#initialize(app, transport) ⇒ AuthorizationRecorder
constructor
A new instance of AuthorizationRecorder.
-
#on_complete(env) ⇒ Object
The bytes are in hand and nothing of the host's has run on them yet: the TTL of whatever this response carries starts here (MCP 2026-07-28 caching, "Freshness Calculation") -- or already started, when the response was read as a stream.
- #on_request(env) ⇒ Object
Constructor Details
#initialize(app, transport) ⇒ AuthorizationRecorder
Returns a new instance of AuthorizationRecorder.
86 87 88 89 |
# File 'lib/mcp_client/http_transport_base/cache_support.rb', line 86 def initialize(app, transport) super(app) @transport = transport end |
Instance Method Details
#on_complete(env) ⇒ Object
The bytes are in hand and nothing of the host's has run on them yet: the TTL of whatever this response carries starts here (MCP 2026-07-28 caching, "Freshness Calculation") -- or already started, when the response was read as a stream.
104 105 106 |
# File 'lib/mcp_client/http_transport_base/cache_support.rb', line 104 def on_complete(env) env[RESPONSE_RECEIVED_AT_KEY] ||= @transport.send(:monotonic_now) end |
#on_request(env) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/mcp_client/http_transport_base/cache_support.rb', line 91 def on_request(env) @transport.send(:note_request_authorization, MCPClient::ResultCaching.(env.request_headers)) env[SENT_AUTHORIZATION_KEY] = @transport.send(:recorded_request_authorization) # Each attempt the retry middleware makes is received on its own. env[RESPONSE_RECEIVED_AT_KEY] = nil stamp_response_chunk(env) end |