Skip to content

Commit 2032bb0

Browse files
authored
Merge pull request #1110 from clue-labs/headless
Fix rejecting invalid HTTP request starting with newlines
2 parents c285cf9 + 1a0d123 commit 2032bb0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Ratchet/Http/HttpRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function onMessage(ConnectionInterface $context, $data) {
5151
* @return boolean
5252
*/
5353
public function isEom($message) {
54-
return (boolean)strpos($message, static::EOM);
54+
return strpos($message, static::EOM) !== false;
5555
}
5656

5757
/**

tests/unit/Http/HttpRequestParserTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ public function testBufferOverflowResponse() {
5050
$this->parser->onMessage($conn, "Header-Is: Too Big");
5151
}
5252

53+
public function testOnMessageThrowsExceptionForEmptyNewlines() {
54+
$conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
55+
56+
if (method_exists($this, 'expectException')) {
57+
$this->expectException('InvalidArgumentException');
58+
} else {
59+
$this->setExpectedException('InvalidArgumentException');
60+
}
61+
62+
$this->parser->onMessage($conn, "\r\n\r\n");
63+
}
64+
5365
public function testReturnTypeIsRequest() {
5466
$conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
5567
$return = $this->parser->onMessage($conn, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n");

0 commit comments

Comments
 (0)