diff --git a/src/Proxy.php b/src/Proxy.php index 5398983..f4dc93c 100644 --- a/src/Proxy.php +++ b/src/Proxy.php @@ -88,7 +88,7 @@ public function response(string $file, ?Options $options = null, array $headers } foreach ($responseHeaders as $header => $values) { - if (true === str_starts_with($header, 'x-')) { + if (true === str_starts_with($header, 'x-') || true === str_starts_with($header, 'cf-')) { $newResponse->headers->set($header, $values); } } diff --git a/tests/ProxyTest.php b/tests/ProxyTest.php index 0b329d3..fdda344 100644 --- a/tests/ProxyTest.php +++ b/tests/ProxyTest.php @@ -76,6 +76,8 @@ public function testResponseFetchesCdnAndCopiesWhitelistedHeaders(): void 'x-content-type-options' => ['nosniff'], 'x-dominant-color' => ['#ff0000'], 'x-custom-header' => ['custom-value'], + 'cf-cache-status' => ['HIT'], + 'cf-ray' => ['abc123-CDG'], ], ] ) @@ -91,6 +93,8 @@ public function testResponseFetchesCdnAndCopiesWhitelistedHeaders(): void self::assertSame('nosniff', $response->headers->get('x-content-type-options')); self::assertSame('#ff0000', $response->headers->get('x-dominant-color')); self::assertSame('custom-value', $response->headers->get('x-custom-header')); + self::assertSame('HIT', $response->headers->get('cf-cache-status')); + self::assertSame('abc123-CDG', $response->headers->get('cf-ray')); } public function testResponseSetsNoCacheControlHeader(): void @@ -133,6 +137,26 @@ public function testResponseForwardsAllXPrefixedHeaders(): void self::assertSame('my-value', $response->headers->get('x-my-custom')); } + public function testResponseForwardsAllCfPrefixedHeaders(): void + { + $client = new MockHttpClient( + new MockResponse( + 'content', + [ + 'response_headers' => [ + 'cf-cache-status' => ['MISS'], + 'cf-ray' => ['xyz789-LHR'], + ], + ] + ) + ); + + $response = $this->makeProxy($client)->response('image.jpg'); + + self::assertSame('MISS', $response->headers->get('cf-cache-status')); + self::assertSame('xyz789-LHR', $response->headers->get('cf-ray')); + } + public function testResponseNormalizesFileStrippingLeadingSlash(): void { $requestedUrl = '';