diff --git a/CHANGELOG.md b/CHANGELOG.md index aa86d7c..868ec0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,9 +27,9 @@ shared by `Renderer` and `SsrPublish`. `render()` returns `RenderedEmbed` hardening. `health()` and `warm()`. `Testing\FakeSsrTransport`. - PHPStan at max, `composer validate --strict`, `--prefer-lowest` CI, `failOnDeprecation`. `SECURITY.md`. -- Streams fallback reads `$http_response_header` in the `file_get_contents` - caller (PHP < 8.4). That identifier lives in a class loaded only then, so - PHP 8.5 does not compile the deprecation. `$GLOBALS` is empty there. +- Streams fallback reads the response headers from the stream metadata + (`stream_get_meta_data()`), not `$http_response_header` (deprecated in + PHP 8.5) or `$GLOBALS` (empty there). One code path for PHP 8.2–8.5. ## 0.3.0 — 2026-09-12 diff --git a/src/Embed/LegacyHttpStreamFetch.php b/src/Embed/LegacyHttpStreamFetch.php deleted file mode 100644 index 0a50f41..0000000 --- a/src/Embed/LegacyHttpStreamFetch.php +++ /dev/null @@ -1,27 +0,0 @@ - $http - * @return array{0: string, 1: list} - */ - public static function get(string $url, array $http): array - { - $body = @file_get_contents($url, false, stream_context_create(['http' => $http])); - if ($body === false) { - throw new SsrUnavailable('SSR request failed'); - } - - return [$body, $http_response_header]; - } -} diff --git a/src/Embed/NativeSsrTransport.php b/src/Embed/NativeSsrTransport.php index b8730c2..8534b47 100644 --- a/src/Embed/NativeSsrTransport.php +++ b/src/Embed/NativeSsrTransport.php @@ -86,21 +86,24 @@ private function withStreams(SsrHttpRequest $request): SsrHttpResponse $http['content'] = $request->body; } - // PHP 8.5 deprecates the $http_response_header identifier itself. - // Keep that name out of this file; PHP < 8.4 loads a sidecar class. - if (function_exists('http_get_last_response_headers')) { - $body = @file_get_contents($request->url, false, stream_context_create(['http' => $http])); - if ($body === false) { - throw new SsrUnavailable('SSR request failed'); - } + // Read the response headers from the stream metadata: PHP 8.5 + // deprecates $http_response_header, and http_get_last_response_headers() + // needs PHP 8.4. + $stream = @fopen($request->url, 'rb', false, stream_context_create(['http' => $http])); + if ($stream === false) { + throw new SsrUnavailable('SSR request failed'); + } - return $this->responseFromHeaderLines( - $this->stringLines(http_get_last_response_headers()), - $body, - ); + try { + $headers = stream_get_meta_data($stream)['wrapper_data'] ?? null; + $body = stream_get_contents($stream); + } finally { + fclose($stream); } - [$body, $headers] = LegacyHttpStreamFetch::get($request->url, $http); + if ($body === false) { + throw new SsrUnavailable('SSR request failed'); + } return $this->responseFromHeaderLines($this->stringLines($headers), $body); }