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 443 as SERVER_PORT(default) when request is https #2323

Merged
merged 8 commits into from
Nov 3, 2017

Conversation

juanpagfe
Copy link

Hi. I solved the #2318 issue. Just added a validation wich changes the default port when request is HTTPS to 443.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 93.227% when pulling 706d94f on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 93.235% when pulling ce3eb14 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 93.235% when pulling 63ba688 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

Copy link
Member

@akrabat akrabat left a comment

Choose a reason for hiding this comment

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

Some changes required as noted.

Also, please supply a unit test so that we don't regress your fix.

//Validates if default protocol is HTTPS to set default port 443
$defport = (isset($userData["HTTPS"]) ||
(isset($userData["SERVER_PROTOCOL"]) && substr($userData["SERVER_PROTOCOL"], 0, 5) === "HTTPS"))
? 443 : 80;
Copy link
Member

Choose a reason for hiding this comment

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

Please use an if statement.

@@ -29,14 +29,19 @@ class Environment extends Collection implements EnvironmentInterface
*/
public static function mock(array $userData = [])
{
//Validates if default protocol is HTTPS to set default port 443
$defport = (isset($userData["HTTPS"]) ||
Copy link
Member

Choose a reason for hiding this comment

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

["HTTPS"] may contain the string off, which should use port 80.

@@ -29,14 +29,19 @@ class Environment extends Collection implements EnvironmentInterface
*/
public static function mock(array $userData = [])
{
//Validates if default protocol is HTTPS to set default port 443
$defport = (isset($userData["HTTPS"]) ||
(isset($userData["SERVER_PROTOCOL"]) && substr($userData["SERVER_PROTOCOL"], 0, 5) === "HTTPS"))
Copy link
Member

Choose a reason for hiding this comment

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

[SERVER_PROTOCOL] will contain HTTP/1.0, HTTP/1.1 or HTTP/2. It will never contain HTTPS and so please do not check this key.

@@ -29,14 +29,19 @@ class Environment extends Collection implements EnvironmentInterface
*/
public static function mock(array $userData = [])
{
//Validates if default protocol is HTTPS to set default port 443
$defport = (isset($userData["HTTPS"]) ||
Copy link
Member

Choose a reason for hiding this comment

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

Use single quoted strings if there's no variable interpolation.

@mahagr
Copy link

mahagr commented Nov 2, 2017

Why not use REQUEST_SCHEME which is either http or https?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 93.243% when pulling 4538ba0 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

@akrabat
Copy link
Member

akrabat commented Nov 2, 2017

Why not use REQUEST_SCHEME which is either http or https?

No reason that it also couldn't be checked. I hadn't heard of it, so didn't mention it.

$data = array_merge([
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'REQUEST_SCHEME' => 'http',
Copy link
Member

@akrabat akrabat Nov 2, 2017

Choose a reason for hiding this comment

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

If you are going to put REQUEST_SCHEME here, then it needs to be either http or https

Similarly, if you're going to support it here, you should test for it in $userData for setting the port.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 93.243% when pulling 0957d80 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 93.243% when pulling 59d4e73 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 93.255% when pulling a3b12b4 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

phpunit.xml.dist Outdated
@@ -12,7 +12,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnFailure="true"
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this change.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 93.255% when pulling a7802a9 on juanpagfe:mock-https-request into 403b798 on slimphp:3.x.

@akrabat akrabat added this to the 3.9.0 milestone Nov 3, 2017
@akrabat akrabat merged commit a7802a9 into slimphp:3.x Nov 3, 2017
@akrabat
Copy link
Member

akrabat commented Nov 3, 2017

Thank you @juanpagfe :)

@akrabat
Copy link
Member

akrabat commented Nov 4, 2017

@juanpagfe Fancy creating a similar PR for https://github.com/slimphp/Slim-Http ?

@mahagr
Copy link

mahagr commented Nov 6, 2017

@akrabat Any change making the same change into Uri class:

https://github.com/slimphp/Slim/blob/3.x/Slim/Http/Uri.php#L169-L170

Mostly because of HTTPS isn't always available.

@akrabat
Copy link
Member

akrabat commented Nov 6, 2017

@mahagr Which web server doesn’t set HTTPS when the connection is over TLS?

@mahagr
Copy link

mahagr commented Nov 6, 2017

See discussion in:

getgrav/grav@a9c8271
getgrav/grav#1698

@juanpagfe
Copy link
Author

@akrabat Of course, I'll create a PR in a minute.

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

Successfully merging this pull request may close these issues.

4 participants