Skip to content

Commit d97150b

Browse files
committed
Send HTTP status code 431 is request header is too large
1 parent 5893c2e commit d97150b

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
@@ -90,7 +90,7 @@ public function handleConnection(ConnectionInterface $conn)
9090

9191
$that->writeError(
9292
$conn,
93-
400
93+
($e instanceof \OverflowException) ? 431 : 400
9494
);
9595
});
9696
}

tests/ServerTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,37 @@ function ($data) use (&$buffer) {
202202
$this->assertContains("\r\nX-Powered-By: React/alpha\r\n", $buffer);
203203
}
204204

205-
public function testParserErrorEmitted()
205+
public function testRequestOverflowWillEmitErrorAndSendErrorResponse()
206206
{
207207
$error = null;
208208
$server = new Server($this->socket);
209209
$server->on('error', function ($message) use (&$error) {
210210
$error = $message;
211211
});
212212

213+
$buffer = '';
214+
215+
$this->connection
216+
->expects($this->any())
217+
->method('write')
218+
->will(
219+
$this->returnCallback(
220+
function ($data) use (&$buffer) {
221+
$buffer .= $data;
222+
}
223+
)
224+
);
225+
213226
$this->socket->emit('connection', array($this->connection));
214227

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

219232
$this->assertInstanceOf('OverflowException', $error);
233+
234+
$this->assertContains("HTTP/1.1 431 Request Header Fields Too Large\r\n", $buffer);
235+
$this->assertContains("\r\n\r\nError 431: Request Header Fields Too Large", $buffer);
220236
}
221237

222238
public function testRequestInvalidWillEmitErrorAndSendErrorResponse()

0 commit comments

Comments
 (0)