Skip to content

Commit 3956bbf

Browse files
committed
Simplify request validation
1 parent d61ee63 commit 3956bbf

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"require": {
1717
"php": ">=5.3",
1818
"react/event-loop": "~0.4.0|~0.3.0",
19-
"react/http": "~0.4.0|~0.3.0",
19+
"react/http": "^0.4.4",
2020
"react/stream": "~0.4.0|~0.3.0"
2121
},
2222
"require-dev": {

examples/01-simple-periodic.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
return;
2020
}
2121

22+
if ($request->getPath() !== '/demo') {
23+
$response->writeHead(404);
24+
$response->end('Not Found');
25+
return;
26+
}
27+
2228
echo 'connected' . PHP_EOL;
2329

24-
$headers = $request->getHeaders();
25-
$id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;
30+
$id = $request->getHeaderLine('Last-Event-ID');
2631

2732
$response->writeHead(200, array('Content-Type' => 'text/event-stream'));
2833
$channel->connect($response, $id);

examples/02-plaintext-chat.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121
return;
2222
}
2323

24+
if ($request->getPath() !== '/demo') {
25+
$response->writeHead(404);
26+
$response->end('Not Found');
27+
return;
28+
}
29+
2430
echo 'connected' . PHP_EOL;
2531

26-
$headers = $request->getHeaders();
27-
$id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;
32+
$id = $request->getHeaderLine('Last-Event-ID');
2833

2934
$response->writeHead(200, array('Content-Type' => 'text/event-stream'));
3035
$channel->connect($response, $id);

examples/03-redis-subscribe.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
return;
2121
}
2222

23+
if ($request->getPath() !== '/demo') {
24+
$response->writeHead(404);
25+
$response->end('Not Found');
26+
return;
27+
}
28+
2329
echo 'connected' . PHP_EOL;
2430

25-
$headers = $request->getHeaders();
26-
$id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;
31+
$id = $request->getHeaderLine('Last-Event-ID');
2732

2833
$response->writeHead(200, array('Content-Type' => 'text/event-stream'));
2934
$channel->connect($response, $id);

0 commit comments

Comments
 (0)