@@ -2941,7 +2941,7 @@ public function fromGlobals(): ServerRequestInterface
2941
2941
2942
2942
$ headers = \function_exists ('getallheaders ' ) ? getallheaders () : static ::getHeadersFromServer ($ _SERVER );
2943
2943
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 );
2945
2945
}
2946
2946
2947
2947
/**
@@ -3132,22 +3132,30 @@ private function createUriFromArray(array $server): UriInterface
3132
3132
{
3133
3133
$ uri = $ this ->uriFactory ->createUri ('' );
3134
3134
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
+ }
3139
3147
}
3140
3148
3141
3149
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
+ }
3143
3155
} elseif (isset ($ server ['SERVER_NAME ' ])) {
3144
3156
$ uri = $ uri ->withHost ($ server ['SERVER_NAME ' ]);
3145
3157
}
3146
3158
3147
- if (isset ($ server ['SERVER_PORT ' ])) {
3148
- $ uri = $ uri ->withPort ($ server ['SERVER_PORT ' ]);
3149
- }
3150
-
3151
3159
if (isset ($ server ['REQUEST_URI ' ])) {
3152
3160
$ uri = $ uri ->withPath (\current (\explode ('? ' , $ server ['REQUEST_URI ' ])));
3153
3161
}
0 commit comments