Add server-side parameters to request object#174
Conversation
src/Server.php
Outdated
| } | ||
|
|
||
| $request = $request->withServerParams($serverParams); | ||
|
|
There was a problem hiding this comment.
Does it make sense to move this whole block to the request parser instead? 👍
README.md
Outdated
| Unix timestamp when the complete request header has been received, | ||
| as float similar to `microtime(true)` | ||
| * `https` | ||
| Set to 'on' if the request used HTTPS, otherwise it will be set to `null` |
There was a problem hiding this comment.
AFAICT $_SERVER['https'] will be unset for plain HTTP, does it really make sense to assume a null value here?
examples/02-client-ip.php
Outdated
|
|
||
| $server = new \React\Http\Server($socket, function (ServerRequestInterface $request) { | ||
| $body = "The method of the request is: " . $request->getMethod(); | ||
| $body .= "The requested path is: " . $request->getUri()->getPath(); |
There was a problem hiding this comment.
?! Does not match example from the README.
There was a problem hiding this comment.
Oopsie. Wrong example.
|
Doesn't it make sense to make the keys match the keys from |
|
@jsor I have no preference here as the keys are rather arbitrary anyway, how do others handle this? |
|
Most PSR7 implementations pass https://github.com/zendframework/zend-diactoros/blob/master/src/ServerRequestFactory.php#L59 So, i think it makes sense to follow common behaviour. |
0cf4b27 to
dc008c0
Compare
src/Server.php
Outdated
|
|
||
| /** @internal */ | ||
| public function handleRequest(ConnectionInterface $conn, ServerRequestInterface $request) | ||
| public function handleRequest(ConnectionInterface $conn, ServerRequest $request) |
There was a problem hiding this comment.
Nope you are right.
src/RequestHeaderParser.php
Outdated
| 'REQUEST_TIME_FLOAT' => microtime(true) | ||
| ); | ||
|
|
||
| if (!empty($this->remoteAddress)) { |
There was a problem hiding this comment.
Not a big fan of empty() here ("0" could technically be a valid UDS address). Does it make sense to use a null check here and below?
There was a problem hiding this comment.
Replaced empty() in newest commit.
src/RequestHeaderParser.php
Outdated
| public function __construct($localSocketUri = '', $remoteAddress = '') | ||
| { | ||
| $this->uri = $localSocketUri; | ||
| $this->remoteAddress = $remoteAddress; |
There was a problem hiding this comment.
Naming convention is a bit unclear WRT local address / URI?
There was a problem hiding this comment.
Renamed vars in newest commit.
examples/02-client-ip.php
Outdated
| $socket = new Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0', $loop); | ||
|
|
||
| $server = new \React\Http\Server($socket, function (ServerRequestInterface $request) { | ||
| $body = "Your IP is: " . $request->getServerParams()['remote_address']; |
3eab518 to
677076c
Compare
|
Ping @clue Added some tests to the |
This PR adds server-side parameters similar to parameters of the $_SERVER from PHP.
This should cover the most important parameters.