Skip to content

Conversation

@clue
Copy link
Member

@clue clue commented Feb 10, 2017

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

@clue clue added the bug label Feb 10, 2017
@clue clue added this to the v0.4.4 milestone Feb 10, 2017
$http->on('request', function (Request $request, Response $response) {
if ($request->expectsContinue()) {
$response->writeContinue();
}
Copy link

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.

Copy link
Member Author

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? 👍

Copy link

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?

Copy link
Member Author

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.

Copy link

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
);
}
Copy link

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?

Copy link
Member Author

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');
Copy link

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.

Copy link

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks! 👍

@clue
Copy link
Member Author

clue commented Feb 11, 2017

Ping, afaict everything's been resolved :shipit:

@clue clue changed the title Fix headers to be handled case insensitive and add documentation for writeHead() and writeContinue() Fix headers to be handled case insensitive and ignore 100-continue for HTTP/1.0 Feb 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Header names are not case-sensitive Remove X-Powered-By: React/alpha or make optional

4 participants