Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server-side parameters to request object #174

Merged
merged 2 commits into from
Apr 26, 2017

Conversation

legionth
Copy link
Contributor

This PR adds server-side parameters similar to parameters of the $_SERVER from PHP.

This should cover the most important parameters.

@WyriHaximus WyriHaximus requested review from jsor and clue April 23, 2017 09:01
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

src/Server.php Outdated
}

$request = $request->withServerParams($serverParams);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT $_SERVER['https'] will be unset for plain HTTP, does it really make sense to assume a null value here?


$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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?! Does not match example from the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsie. Wrong example.

@jsor
Copy link
Member

jsor commented Apr 23, 2017

Doesn't it make sense to make the keys match the keys from $_SERVER? Eg. remote_address -> REMOTE_ADDR.

@clue
Copy link
Member

clue commented Apr 23, 2017

@jsor I have no preference here as the keys are rather arbitrary anyway, how do others handle this?

@jsor
Copy link
Member

jsor commented Apr 23, 2017

Most PSR7 implementations pass $_SERVER in as is.

https://github.com/zendframework/zend-diactoros/blob/master/src/ServerRequestFactory.php#L59
https://github.com/guzzle/psr7/blob/master/src/ServerRequest.php#L174
https://github.com/slimphp/Slim/blob/3.x/Slim/DefaultServicesProvider.php#L47

So, i think it makes sense to follow common behaviour.

@clue
Copy link
Member

clue commented Apr 24, 2017

@jsor Thanks for digging this up and I concur, @legionth can you update this? 👍

@legionth legionth force-pushed the server-params branch 2 times, most recently from 0cf4b27 to dc008c0 Compare April 24, 2017 11:15
@legionth
Copy link
Contributor Author

Ping @jsor renamed the server params.

Ping @clue Moved the code to RequestHeaderParser. Also changed the behavior of the HTTPS key. Have a look.

src/Server.php Outdated
@@ -174,7 +175,7 @@ public function handleConnection(ConnectionInterface $conn)
}

/** @internal */
public function handleRequest(ConnectionInterface $conn, ServerRequestInterface $request)
public function handleRequest(ConnectionInterface $conn, ServerRequest $request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope you are right.

'REQUEST_TIME_FLOAT' => microtime(true)
);

if (!empty($this->remoteAddress)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced empty() in newest commit.

{
$this->uri = $localSocketUri;
$this->remoteAddress = $remoteAddress;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming convention is a bit unclear WRT local address / URI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed vars in newest commit.

$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'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😨

@legionth legionth force-pushed the server-params branch 3 times, most recently from 3eab518 to 677076c Compare April 24, 2017 13:35
@legionth
Copy link
Contributor Author

Ping @clue Added some tests to the RequestHeaderParser.

@clue clue added this to the v0.7.0 milestone Apr 26, 2017
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, changes LGTM! :shipit: 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants