Skip to content

Commit 3f882d1

Browse files
committed
Send HTTP status code 431 if request header is too large
1 parent 8dfc3a3 commit 3f882d1

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function handleConnection(ConnectionInterface $conn)
101101

102102
$that->writeError(
103103
$conn,
104-
400
104+
($e instanceof \OverflowException) ? 431 : 400
105105
);
106106
});
107107
}

tests/ServerTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,37 @@ function ($data) use (&$buffer) {
308308
$this->assertContains("\r\n\r\nError 505: HTTP Version Not Supported", $buffer);
309309
}
310310

311-
public function testParserErrorEmitted()
311+
public function testRequestOverflowWillEmitErrorAndSendErrorResponse()
312312
{
313313
$error = null;
314314
$server = new Server($this->socket);
315315
$server->on('error', function ($message) use (&$error) {
316316
$error = $message;
317317
});
318318

319+
$buffer = '';
320+
321+
$this->connection
322+
->expects($this->any())
323+
->method('write')
324+
->will(
325+
$this->returnCallback(
326+
function ($data) use (&$buffer) {
327+
$buffer .= $data;
328+
}
329+
)
330+
);
331+
319332
$this->socket->emit('connection', array($this->connection));
320333

321334
$data = "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\nX-DATA: ";
322335
$data .= str_repeat('A', 4097 - strlen($data)) . "\r\n\r\n";
323336
$this->connection->emit('data', array($data));
324337

325338
$this->assertInstanceOf('OverflowException', $error);
339+
340+
$this->assertContains("HTTP/1.1 431 Request Header Fields Too Large\r\n", $buffer);
341+
$this->assertContains("\r\n\r\nError 431: Request Header Fields Too Large", $buffer);
326342
}
327343

328344
public function testRequestInvalidWillEmitErrorAndSendErrorResponse()

0 commit comments

Comments
 (0)