-
-
Notifications
You must be signed in to change notification settings - Fork 167
Fix headers to be handled case insensitive and ignore 100-continue for HTTP/1.0 #107
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
Conversation
| $http->on('request', function (Request $request, Response $response) { | ||
| if ($request->expectsContinue()) { | ||
| $response->writeContinue(); | ||
| } |
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.
How can I access the actual request body then? I think this should be handled transparently.
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.
This only adds documentation for the existing behavior, accessing the request body is not part of this 👍 (see also #104 and #105)
That being said and given the current architecture, I think it's very reasonable to handle this explicitly. The documentation explicitly states why the consumer of this lib is in control of this behavior. (see also #47)
Note that I'm not saying this has to stay that way, but I'd rather discuss this in a separate feature ticket instead (BC break ahead). Do you feel like filing one? 👍
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.
If I write code like documented now, how does reading the request body work then? Do I have to find it out manually and discard the first expect 100 request?
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.
See the existing and the updated documentation: The Request implements ReadableStreamInterface, so you can read the request body by awaiting the data events and wait for a final end event.
Note that this is somewhat limited until #104 is resolved, which is something I'm currently looking into with @legionth 👍
Note that this is actually only a single request, so nothing is being "discarded" here.
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.
@clue Remembered it wrong, thought expect-100 would send the request headers again then.
| array('X-Powered-By' => 'React/alpha'), | ||
| $headers | ||
| ); | ||
| } |
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.
This should probably update $lower, too?
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.
The $lower is only used within this method, so it's not needed anymore after this assignment.
src/Request.php
Outdated
| public function expectsContinue() | ||
| { | ||
| return isset($this->headers['Expect']) && '100-continue' === $this->headers['Expect']; | ||
| return '100-continue' === $this->getHeaderLine('Expect'); |
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.
This needs a strtolower call for $this->getHeaderLine("expect"), see https://tools.ietf.org/html/rfc7231#section-5.1.1
The Expect field-value is case-insensitive.
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.
This should also check the protocol version, as it must return false for HTTP/1.0.
A server that receives a 100-continue expectation in an HTTP/1.0 request MUST ignore that expectation.
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.
Good catch, thanks! 👍
|
Ping, afaict everything's been resolved |
writeHead() and writeContinue()
This simple PR makes sure we always match header names case insensitive.
Also adds some documentation for the existing methods.
Builds on top of #103
Fixes / closes #51
Fixes / closes #36
Supersedes / closes #54
Supersedes #53
Supersedes #47