-
-
Notifications
You must be signed in to change notification settings - Fork 143
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 PSR-7 ServerRequestInterface to the PSR-7 Request #160
Conversation
src/ServerRequest.php
Outdated
|
||
if (!isset($cookies[$key])) { | ||
$result[$key] = $value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests for multiple cookies with the same name and those using special chars?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid reference?
README.md
Outdated
[PSR-7 RequestInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#32-psrhttpmessagerequestinterface) | ||
and implements the | ||
[PSR-7 ServerRequestInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#321-psrhttpmessageserverrequestinterface) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…implements the ServerRequestInterface which in turn extends the RequestInterface?
README.md
Outdated
@@ -269,6 +273,20 @@ $http = new Server($socket, function (RequestInterface $request) { | |||
}); | |||
``` | |||
|
|||
As mentioned before the request implements the `ServerRequestInterface`. | |||
The `Server` will add server-side parameters like the remote address or cookies | |||
this object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…to this object.
README.md
Outdated
return new Response( | ||
200, | ||
array('Content-Type' => 'text/plain'), | ||
"The remote: " . $request->getServerParams()['remote_address'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this name come from, are there any other params? (needs some documentation)
src/ServerRequest.php
Outdated
|
||
if (preg_match('(\,)', $cookie) >= 1) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be moved up and could use some documentation? Looks like strpos()
?
Just wanted to ask if we really need our own implementation of |
@maciejmrozinski I think you're raising a valid point here 👍 I'm perfectly fine with switching to any other PSR-7 implementation because we only expose its interfaces and everything else is basically just an implementation detail. In this particular case, this PR only adds a very simple implementation of the Switching to another implementation now would create a bigger changeset and would likely break compatibility with legacy PHP < 5.4 (which I'm not saying is a deal-breaker), but I suppose this is best left up to another PR? 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File Server.php should be reviewed for RequestInterface
methods parameters and occurrences should be changed to ServerRequestInterface
.
Lines: 8, 170, 194, 333, 357
6a5d5a3
to
f736962
Compare
Ping @clue. I think added all the changes you mentioned. |
@legionth how about this #160 (review) ? Should it be changed or |
README.md
Outdated
Unix timestamp of the moment, the complete request header was received | ||
* `request_time_float` | ||
Unix timestamp in microseconds of the moment, the complete request header wa | ||
received |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this list come from? (ref please)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an reference to the text and an example.
README.md
Outdated
received | ||
|
||
The cookies of the request, will also be added to the request object by the `Server`. | ||
Use the `getCookies` method to receive these cookies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added example and more explanation for the cookies.
README.md
Outdated
The `Server` will currently add several server-side parameters to the request like: | ||
|
||
* `server_address` | ||
The current IP address of the server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the port?
src/ServerRequest.php
Outdated
|
||
if (!isset($cookies[$key])) { | ||
$result[$key] = $value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid reference?
src/Server.php
Outdated
@@ -90,6 +106,7 @@ | |||
class Server extends EventEmitter | |||
{ | |||
private $callback; | |||
private $serverAddress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use $conn->getLocalAddress()
instead in case this is a "listen all" address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Restructured the code a bit and added an additional server parameter
cb9d103
to
1802135
Compare
@clue Have look, I added some docuementation and test for the cookies and server params. @maciejmrozinski Thank you! Changed the type hints. Have look |
@legionth looks good to me |
$body | ||
); | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and should also be added to examples/
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to examples/
"Your cookie has been set." | ||
); | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but should probably be merged with above example 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged the two examples into one and added to examples/
tests/ServerRequestTest.php
Outdated
{ | ||
$cookieString = 'hello=world;hello=abc'; | ||
$cookies = ServerRequest::parseCookie($cookieString); | ||
$this->assertEquals(array('hello' => 'world'), $cookies); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not saying this is wrong, but this is certainly unexpected. Does this need explicit documentation or is this common behavior / does this follow a common implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked the $_COOKIE
behavior of PHP. Changed the behavior a bit, have a look.
I'm working with @maciejmrozinski at porting php-pm to the next react/http version based on this PR. After only getting 400 responses I've dug into the
Any idea what might be wrong here? |
Update fixed for me by changing the socket
Should I open an issue at socket? Or is it possible that anything in the I've also opened https://bugs.php.net/bug.php?id=74458 for time being. |
pinging @clue I have the suspicion- though I can't find the root cause- that reactphp/socket@a967ef1 might be causing (or not fixing) the problem I'm seeing. Apart from |
@andig Thanks for spotting this and filing reactphp/socket#92 which I think is the correct place to handle this 👍 @legionth This PR should probably be rebased now that #167 is in and we should probably add the equivalent of |
1802135
to
1f5ebf8
Compare
1f5ebf8
to
16d0654
Compare
@clue I think this should cover your change requests. Added the |
This PR adds a bit too much features and I can't cover them all. The fact is that this PR gets bigger and bigger, so I decided to open several smaller PRs. |
This PR adds a PSR-ServerRequestInterface to the request.
This PR adds the remote address to the server params(Fixes #153). Also cookies are parsed from the raw request and added to the request object.
Uploaded files are not handled in this PR, because this would be a much bigger task and needs an asynchronous approach(which would be too much to review).
The new class makes it possible to handle parsed request bodies (#105 for v0.8.0).