Skip to content

Commit

Permalink
bug #107 Ignore invalid HTTP headers when creating PSR7 objects (nico…
Browse files Browse the repository at this point in the history
…las-grekas)

This PR was merged into the 2.1-dev branch.

Discussion
----------

Ignore invalid HTTP headers when creating PSR7 objects

Fixes e.g. Nyholm/psr7#167

Commits
-------

9a78a16 Ignore invalid HTTP headers when creating PSR7 objects
  • Loading branch information
nicolas-grekas committed Sep 5, 2022
2 parents bdb2871 + 9a78a16 commit 155a7ae
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 237 deletions.
12 changes: 10 additions & 2 deletions Factory/PsrHttpFactory.php
Expand Up @@ -58,7 +58,11 @@ public function createRequest(Request $symfonyRequest)
);

foreach ($symfonyRequest->headers->all() as $name => $value) {
$request = $request->withHeader($name, $value);
try {
$request = $request->withHeader($name, $value);
} catch (\InvalidArgumentException $e) {
// ignore invalid header
}
}

$body = $this->streamFactory->createStreamFromResource($symfonyRequest->getContent(true));
Expand Down Expand Up @@ -160,7 +164,11 @@ public function createResponse(Response $symfonyResponse)
}

foreach ($headers as $name => $value) {
$response = $response->withHeader($name, $value);
try {
$response = $response->withHeader($name, $value);
} catch (\InvalidArgumentException $e) {
// ignore invalid header
}
}

$protocolVersion = $symfonyResponse->getProtocolVersion();
Expand Down
234 changes: 0 additions & 234 deletions Tests/Factory/AbstractHttpMessageFactoryTest.php

This file was deleted.

0 comments on commit 155a7ae

Please sign in to comment.