Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function toGuzzle(): Request
$this->setAcceptHeaders();
$this->setOnStats();

return new Request($this->method, $this->getURL(), $this->headers, $this->encodeBody());
return new Request($this->method, $this->getURL(), $this->getHeaders(), $this->encodeBody());
}

/**
Expand All @@ -260,7 +260,26 @@ public function getArguments(): array
}

/**
* Simple readonly getter to read the headers so far.
* Getter for the headers to be sent with the request. Called by toGuzzle() immediately before send,
* so it is the preferred place to attach headers that must be computed freshly (e.g., pulled from a
* secrets store, or a compiled JWT) rather than set once in __construct().
*
* This matters for AbstractUseStaleRequest: the background refresh job serializes/unserializes a clone
* of the request, so anything only set in __construct() (or otherwise stored as plain state) reflects
* whatever it was at the time of the *original* request, not a fresh value at refresh time. Overriding
* getHeaders() (the same pattern used by getCacheTags()) instead of relying on the $headers property
* ensures the value is recomputed every time the request is actually sent, both before and after
* serialization.
*
* @example
* public function getHeaders(): array
* {
* return [
* ...parent::getHeaders(),
* 'Authorization' => 'Bearer ' . $this->fetchToken(),
* ];
* }
*
* @return array
*/
public function getHeaders(): array
Expand Down