-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
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.
Some changes required as noted.
Also, please supply a unit test so that we don't regress your fix.
Slim/Http/Environment.php
Outdated
//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; |
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.
Please use an if
statement.
Slim/Http/Environment.php
Outdated
@@ -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"]) || |
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.
["HTTPS"]
may contain the string off
, which should use port 80.
Slim/Http/Environment.php
Outdated
@@ -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")) |
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.
[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.
Slim/Http/Environment.php
Outdated
@@ -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"]) || |
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.
Use single quoted strings if there's no variable interpolation.
Why not use |
No reason that it also couldn't be checked. I hadn't heard of it, so didn't mention it. |
Slim/Http/Environment.php
Outdated
$data = array_merge([ | ||
'SERVER_PROTOCOL' => 'HTTP/1.1', | ||
'REQUEST_METHOD' => 'GET', | ||
'REQUEST_SCHEME' => 'http', |
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 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.
phpunit.xml.dist
Outdated
@@ -12,7 +12,7 @@ | |||
convertNoticesToExceptions="true" | |||
convertWarningsToExceptions="true" | |||
processIsolation="false" | |||
stopOnFailure="false" | |||
stopOnFailure="true" |
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.
Please remove this change.
Thank you @juanpagfe :) |
@juanpagfe Fancy creating a similar PR for https://github.com/slimphp/Slim-Http ? |
@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. |
@mahagr Which web server doesn’t set |
See discussion in: |
@akrabat Of course, I'll create a PR in a minute. |
Hi. I solved the #2318 issue. Just added a validation wich changes the default port when request is HTTPS to 443.