Skip to content

Commit 00ad891

Browse files
committed
fix for #602
1 parent 341fe34 commit 00ad891

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

api.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ public function fromGlobals(): ServerRequestInterface
29412941

29422942
$headers = \function_exists('getallheaders') ? getallheaders() : static::getHeadersFromServer($_SERVER);
29432943

2944-
return $this->fromArrays($server, $headers, $_COOKIE, $_GET, $_POST, $_FILES, fopen('php://input', 'r') ?: null);
2944+
return $this->fromArrays($server, $headers, $_COOKIE, $_GET, $_POST, $_FILES, \fopen('php://input', 'r') ?: null);
29452945
}
29462946

29472947
/**
@@ -3132,22 +3132,30 @@ private function createUriFromArray(array $server): UriInterface
31323132
{
31333133
$uri = $this->uriFactory->createUri('');
31343134

3135-
if (isset($server['REQUEST_SCHEME'])) {
3136-
$uri = $uri->withScheme($server['REQUEST_SCHEME']);
3137-
} elseif (isset($server['HTTPS'])) {
3138-
$uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http');
3135+
if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
3136+
$uri = $uri->withScheme($server['HTTP_X_FORWARDED_PROTO']);
3137+
} else {
3138+
if (isset($server['REQUEST_SCHEME'])) {
3139+
$uri = $uri->withScheme($server['REQUEST_SCHEME']);
3140+
} elseif (isset($server['HTTPS'])) {
3141+
$uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http');
3142+
}
3143+
3144+
if (isset($server['SERVER_PORT'])) {
3145+
$uri = $uri->withPort($server['SERVER_PORT']);
3146+
}
31393147
}
31403148

31413149
if (isset($server['HTTP_HOST'])) {
3142-
$uri = $uri->withHost($server['HTTP_HOST']);
3150+
if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
3151+
$uri = $uri->withHost($matches[1])->withPort($matches[2]);
3152+
} else {
3153+
$uri = $uri->withHost($server['HTTP_HOST']);
3154+
}
31433155
} elseif (isset($server['SERVER_NAME'])) {
31443156
$uri = $uri->withHost($server['SERVER_NAME']);
31453157
}
31463158

3147-
if (isset($server['SERVER_PORT'])) {
3148-
$uri = $uri->withPort($server['SERVER_PORT']);
3149-
}
3150-
31513159
if (isset($server['REQUEST_URI'])) {
31523160
$uri = $uri->withPath(\current(\explode('?', $server['REQUEST_URI'])));
31533161
}

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)