Skip to content

Commit 8331b41

Browse files
committed
Throw the exceptions caught by the request parser so the error handling side of the stack can do something if desired
1 parent c5c6f0d commit 8331b41

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Http/Middleware/ParseHttpRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public function onMessage(Connection $connection, string $data): void
4646
if (!($request = $this->requestParser->parse($connection, $data)) instanceof RequestInterface) {
4747
return;
4848
}
49-
} catch (MalformedRequest) {
49+
} catch (MalformedRequest $exception) {
5050
$this->close($connection, 400);
5151

52-
return;
53-
} catch (MessageTooLarge) {
52+
throw $exception;
53+
} catch (MessageTooLarge $exception) {
5454
$this->close($connection, 413);
5555

56-
return;
56+
throw $exception;
5757
}
5858

5959
$connection->getAttributeStore()->set('http.headers_received', true);

tests/Http/Middleware/ParseHttpRequestTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public function testOnMessageWhenHttpMessageIsInvalid(): void
128128
$this->decoratedMiddleware->expects($this->never())
129129
->method('onOpen');
130130

131+
$this->expectException(MalformedRequest::class);
132+
131133
$this->middleware->onMessage($connection, $message);
132134
}
133135

@@ -159,6 +161,8 @@ public function testOnMessageWhenHttpMessageOverflows(): void
159161
$this->decoratedMiddleware->expects($this->never())
160162
->method('onOpen');
161163

164+
$this->expectException(MessageTooLarge::class);
165+
162166
$this->middleware->onMessage($connection, $message);
163167
}
164168

0 commit comments

Comments
 (0)