Skip to content

Commit 35b83d8

Browse files
committed
Return 404 when no $next callable is passed in
1 parent 41a7c36 commit 35b83d8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/WebSocketMiddleware.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ public function __construct(array $paths = [], callable $connectionHandler = nul
2222
$this->subProtocols = $subProtocols;
2323
}
2424

25-
public function __invoke(ServerRequestInterface $request, callable $next)
25+
public function __invoke(ServerRequestInterface $request, callable $next = null)
2626
{
2727
// check path at some point - for now we just go go ws
2828
if (count($this->paths) > 0) {
2929
if (!in_array($request->getUri()->getPath(), $this->paths)) {
30+
if ($next === null) {
31+
return new Response(404);
32+
}
33+
3034
return $next($request);
3135
}
3236
}
@@ -38,6 +42,10 @@ public function __invoke(ServerRequestInterface $request, callable $next)
3842
$response = $negotiator->handshake($request);
3943

4044
if ($response->getStatusCode() != '101') {
45+
if ($next === null) {
46+
return new Response(404);
47+
}
48+
4149
// TODO: this should return an error or something not continue the chain
4250
return $next($request);
4351
}

0 commit comments

Comments
 (0)