Skip to content

Commit

Permalink
RequestFactory: fixed port detection when HTTP_HOST & SERVER_PORT are…
Browse files Browse the repository at this point in the history
… used [Closes #223]
  • Loading branch information
dg committed Mar 20, 2023
1 parent 9105c26 commit 75c6bb9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function getServer(Url $url): void
$url->setHost(rtrim(strtolower($pair[1]), '.'));
if (isset($pair[2])) {
$url->setPort((int) substr($pair[2], 1));
} elseif (isset($_SERVER['SERVER_PORT'])) {
} elseif ($tmp === 'SERVER_NAME' && isset($_SERVER['SERVER_PORT'])) {
$url->setPort((int) $_SERVER['SERVER_PORT']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Http/RequestFactory.port.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RequestFactoryPortTest extends Tester\TestCase
[8080, ['SERVER_NAME' => 'localhost:8080']],
[8080, ['HTTP_HOST' => 'localhost:8080', 'SERVER_PORT' => '666']],
[8080, ['SERVER_NAME' => 'localhost:8080', 'SERVER_PORT' => '666']],
[8080, ['HTTP_HOST' => 'localhost', 'SERVER_PORT' => '8080']],
[80, ['HTTP_HOST' => 'localhost', 'SERVER_PORT' => '8080']],
[8080, ['SERVER_NAME' => 'localhost', 'SERVER_PORT' => '8080']],

[80, ['HTTP_X_FORWARDED_PORT' => '8080']],
Expand All @@ -41,7 +41,7 @@ class RequestFactoryPortTest extends Tester\TestCase
[8080, ['SERVER_NAME' => 'localhost:8080', 'SERVER_PORT' => '80', 'HTTP_X_FORWARDED_PORT' => '666']],
[80, ['HTTP_HOST' => 'localhost', 'HTTP_X_FORWARDED_PORT' => '666']],
[80, ['SERVER_NAME' => 'localhost', 'HTTP_X_FORWARDED_PORT' => '666']],
[8080, ['HTTP_HOST' => 'localhost', 'SERVER_PORT' => '8080', 'HTTP_X_FORWARDED_PORT' => '666']],
[80, ['HTTP_HOST' => 'localhost', 'SERVER_PORT' => '8080', 'HTTP_X_FORWARDED_PORT' => '666']],
[8080, ['SERVER_NAME' => 'localhost', 'SERVER_PORT' => '8080', 'HTTP_X_FORWARDED_PORT' => '666']],
[44443, ['HTTPS' => 'on', 'SERVER_NAME' => 'localhost:44443', 'HTTP_X_FORWARDED_PORT' => '666']],
];
Expand Down

0 comments on commit 75c6bb9

Please sign in to comment.