Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions tests/Fixtures/Controllers/HeaderWithUnderscoresController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Tests\Tempest\Fixtures\Controllers;

use Tempest\Http\Request;
use Tempest\Http\Responses\Ok;
use Tempest\Router\Get;

final class HeaderWithUnderscoresController
{
#[Get('/header-with-underscores')]
public function __invoke(Request $request): Ok
{
return new Ok()->addHeader('tempest_session_id', $request->headers->get('tempest_session_id'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/Route/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down