Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of raw ipv6 address in host header #378

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

luzrain
Copy link
Contributor

@luzrain luzrain commented Jan 26, 2025

Fixed problem:
If you expose ipv6 and try to get access the server using a raw ipv6 address, you will get a 400 error because regexp could not parse ipv6 properly.

Test code to reproduce
Try to get access to http://127.0.0.1:8085 and http://[fe80::215:5dff:fe67:1d75]:8085 (change ipv6 to your local)

use Amp\Http\Server\DefaultErrorHandler;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\SocketHttpServer;
use Psr\Log\NullLogger;

$logger = new NullLogger();
$errorHandler = new DefaultErrorHandler();
$requestHandler = new class implements RequestHandler {
    public function handleRequest(Request $request) : Response
    {
        return new Response(body: 'Hello, world!');
    }
};

$server = SocketHttpServer::createForDirectAccess($logger);
$server->expose('0.0.0.0:8085');
$server->expose('[::]:8085');
$server->start($requestHandler, $errorHandler);

// Serve requests until SIGINT or SIGTERM is received by the process.
Amp\trapSignal([SIGINT, SIGTERM]);

$server->stop();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant