Skip to content

[HttpFoundation] Find the original request protocol version #21469

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

thewilkybarkid
Copy link
Contributor

@thewilkybarkid thewilkybarkid commented Jan 31, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21415
License MIT
Doc PR

Adds a new method to Request to find the original protocol version from the Via header, if the request is from a trusted proxy.

@thewilkybarkid thewilkybarkid force-pushed the request-original-protocol-version branch from dcad2b9 to 30f246f Compare January 31, 2017 08:56
public function getOriginalProtocolVersion()
{
if ($this->isFromTrustedProxy()) {
preg_match('~^(HTTP/)?([1-9].[0-9]) ~', $this->headers->get('Via'), $matches);
Copy link
Member

Choose a reason for hiding this comment

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

The . must be escaped (currently it matches HTTP/1^1 for instance).

@nicolas-grekas
Copy link
Member

The other methods that use isFromTrustedProxy don't have the "Original" keyword in their name. What about just getProtocolVersion()?
Is there anything else that could be relevant in the "Via" header? Do you have any link documenting its value?

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Jan 31, 2017
@nicolas-grekas
Copy link
Member

Status: needs work

@nicolas-grekas
Copy link
Member

Security issue: why should "Via" be trusted?
Any RFC that defines the semantic of the header?

@dunglas
Copy link
Member

dunglas commented Feb 11, 2017

@thewilkybarkid
Copy link
Contributor Author

@nicolas-grekas I used the term 'original' to distinguish the request that the user originally made (to some proxy) with the one that PHP has received. Happy to rename if there's a more suitable term.

@@ -1536,6 +1536,24 @@ public function isMethodCacheable()
}

/**
* Returns the original protocol version.
Copy link
Member

Choose a reason for hiding this comment

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

This description should be improved to explain very briefly what does "the original protocol" mean. Thanks!

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Feb 13, 2017

We don't make any distinction for "original" host/ip/proto/port. I don't see why this shouldn't be the same for the version of the proto.

@thewilkybarkid
Copy link
Contributor Author

The response should be the protocol version used by the proxy, not the original client, so they need to be kept separate.

@dunglas
Copy link
Member

dunglas commented Feb 13, 2017

Maybe can we add a method to parse the Via header, with a shortcut to only retrieve the value of the first (original) protocol and version used?

It may be interesting to know the original protocol version (for instance to add Link HTTP headers depending of the client capabilities).

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Feb 14, 2017

The response should be the protocol version used by the proxy, not the original client, so they need to be kept separate.

that's exactly my point yes: getHost, isSecure, getPort all return the info as used by the client - not the proxy. This should be the same here to me.
If one wants to get access to the protocol used by the proxy, just call $request->server->get('SERVER_PROTOCOL').

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

👎 Your application is talking to the proxy, so we should return the HTTP protocol of the proxy, not the one used between the client and the proxy. I understand the use case, but that should be done in your application, not in Symfony.

@thewilkybarkid
Copy link
Contributor Author

The protocol version isn't being changed in the response.

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.4 Apr 26, 2017
@fabpot
Copy link
Member

fabpot commented Jul 6, 2017

Thank you @thewilkybarkid.

fabpot added a commit that referenced this pull request Jul 6, 2017
…rsion (thewilkybarkid)

This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #21469).

Discussion
----------

[HttpFoundation] Find the original request protocol version

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21415
| License       | MIT
| Doc PR        |

Adds a new method to `Request` to find the original protocol version from the `Via` header, if the request is from a trusted proxy.

Commits
-------

5a37f84 [HttpFoundation] Find the original request protocol version
@fabpot fabpot closed this Jul 6, 2017
@thewilkybarkid thewilkybarkid deleted the request-original-protocol-version branch July 6, 2017 10:00
This was referenced Oct 18, 2017
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.

6 participants