Skip to content

Commit 5dbbbbe

Browse files
committed
Merge branch 'router-race-fix'
2 parents 5b5795c + 1aafdac commit 5dbbbbe

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace Ratchet\Http;
3+
use Ratchet\ConnectionInterface;
4+
use Psr\Http\Message\RequestInterface;
5+
6+
class NoOpHttpServerController implements HttpServerInterface {
7+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
8+
}
9+
10+
public function onMessage(ConnectionInterface $from, $msg) {
11+
}
12+
13+
public function onClose(ConnectionInterface $conn) {
14+
}
15+
16+
public function onError(ConnectionInterface $conn, \Exception $e) {
17+
}
18+
}

src/Ratchet/Http/Router.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ class Router implements HttpServerInterface {
1515
*/
1616
protected $_matcher;
1717

18+
private $_noopController;
19+
1820
public function __construct(UrlMatcherInterface $matcher) {
1921
$this->_matcher = $matcher;
22+
$this->_noopController = new NoOpHttpServerController;
2023
}
2124

2225
/**
@@ -28,6 +31,8 @@ public function onOpen(ConnectionInterface $conn, RequestInterface $request = nu
2831
throw new \UnexpectedValueException('$request can not be null');
2932
}
3033

34+
$conn->controller = $this->_noopController;
35+
3136
$uri = $request->getUri();
3237

3338
$context = $this->_matcher->getContext();
@@ -67,14 +72,14 @@ public function onOpen(ConnectionInterface $conn, RequestInterface $request = nu
6772
/**
6873
* {@inheritdoc}
6974
*/
70-
function onMessage(ConnectionInterface $from, $msg) {
75+
public function onMessage(ConnectionInterface $from, $msg) {
7176
$from->controller->onMessage($from, $msg);
7277
}
7378

7479
/**
7580
* {@inheritdoc}
7681
*/
77-
function onClose(ConnectionInterface $conn) {
82+
public function onClose(ConnectionInterface $conn) {
7883
if (isset($conn->controller)) {
7984
$conn->controller->onClose($conn);
8085
}
@@ -83,7 +88,7 @@ function onClose(ConnectionInterface $conn) {
8388
/**
8489
* {@inheritdoc}
8590
*/
86-
function onError(ConnectionInterface $conn, \Exception $e) {
91+
public function onError(ConnectionInterface $conn, \Exception $e) {
8792
if (isset($conn->controller)) {
8893
$conn->controller->onError($conn, $e);
8994
}

tests/unit/Http/RouterTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
use Ratchet\WebSocket\WsServerInterface;
44
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
55
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
6+
use Symfony\Component\Routing\RequestContext;
7+
use Symfony\Component\Routing\RouteCollection;
8+
use Symfony\Component\Routing\Matcher\UrlMatcher;
9+
610

711
/**
812
* @covers Ratchet\Http\Router
@@ -142,4 +146,20 @@ public function testQueryParams() {
142146
$this->assertEquals('ws', $request->getUri()->getScheme());
143147
$this->assertEquals('doesnt.matter', $request->getUri()->getHost());
144148
}
149+
150+
public function testImpatientClientOverflow() {
151+
$this->_conn->expects($this->once())->method('close');
152+
153+
$header = "GET /nope HTTP/1.1
154+
Upgrade: websocket
155+
Connection: upgrade
156+
Host: localhost
157+
Origin: http://localhost
158+
Sec-WebSocket-Version: 13\r\n\r\n";
159+
160+
$app = new HttpServer(new Router(new UrlMatcher(new RouteCollection, new RequestContext)));
161+
$app->onOpen($this->_conn);
162+
$app->onMessage($this->_conn, $header);
163+
$app->onMessage($this->_conn, 'Silly body');
164+
}
145165
}

0 commit comments

Comments
 (0)