diff --git a/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php b/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php index bd2a272ea..ecc26b724 100644 --- a/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php +++ b/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php @@ -10,6 +10,8 @@ use Tempest\Http\Session\SessionId; use Tempest\Http\Session\SessionIdResolver; +use function Tempest\Support\str; + final readonly class HeaderSessionIdResolver implements SessionIdResolver { public function __construct( diff --git a/tests/Fixtures/Controllers/HeaderWithUnderscoresController.php b/tests/Fixtures/Controllers/HeaderWithUnderscoresController.php new file mode 100644 index 000000000..a0616b99b --- /dev/null +++ b/tests/Fixtures/Controllers/HeaderWithUnderscoresController.php @@ -0,0 +1,16 @@ +addHeader('tempest_session_id', $request->headers->get('tempest_session_id')); + } +} diff --git a/tests/Integration/Http/SessionFromHeaderTest.php b/tests/Integration/Http/HeaderSessionIdResolverTest.php similarity index 77% rename from tests/Integration/Http/SessionFromHeaderTest.php rename to tests/Integration/Http/HeaderSessionIdResolverTest.php index adb9d3b5b..41ffec6d4 100644 --- a/tests/Integration/Http/SessionFromHeaderTest.php +++ b/tests/Integration/Http/HeaderSessionIdResolverTest.php @@ -9,19 +9,26 @@ use Tempest\Http\Method; use Tempest\Http\Request; use Tempest\Http\Session\Config\FileSessionConfig; +use Tempest\Http\Session\Resolvers\HeaderSessionIdResolver; use Tempest\Http\Session\Session; +use Tempest\Http\Session\SessionIdResolver; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; /** * @internal */ -final class SessionFromHeaderTest extends FrameworkIntegrationTestCase +final class HeaderSessionIdResolverTest extends FrameworkIntegrationTestCase { public function test_resolving_session_from_header(): void { + $this->container->singleton( + SessionIdResolver::class, + $this->container->get(HeaderSessionIdResolver::class), + ); + $this->container->config(new FileSessionConfig( - path: 'test_sessions', expiration: Duration::hours(2), + path: 'test_sessions', )); $this->setSessionId('session_a'); diff --git a/tests/Integration/Route/RequestTest.php b/tests/Integration/Route/RequestTest.php index 5648c567c..01d8f2357 100644 --- a/tests/Integration/Route/RequestTest.php +++ b/tests/Integration/Route/RequestTest.php @@ -106,6 +106,19 @@ public function test_custom_request_test(): void $this->assertEquals('test-title test-text', $response->body); } + public function test_headers_with_underscores(): void + { + $this->http + ->get( + uri: '/header-with-underscores', + headers: [ + 'tempest_session_id' => 'test', + ], + ) + ->assertOk() + ->assertHeaderMatches('tempest_session_id', 'test'); + } + public function test_generic_request_can_map_to_custom_request(): void { $response = $this->http