File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,26 @@ public function createServerRequestFromGlobalState(
52
52
$ uri = new Uri ($ server ["REQUEST_URI " ] ?? null );
53
53
$ headers = new RequestHeaders ();
54
54
55
+ if ($ secure = $ server ["HTTPS " ] ?? null ) {
56
+ $ uri = $ uri ->withScheme ("https " );
57
+ }
58
+ else {
59
+ $ uri = $ uri ->withScheme ("http " );
60
+ }
61
+
62
+ if ($ port = $ server ["SERVER_PORT " ] ?? null ) {
63
+ $ uri = $ uri ->withPort ((int )$ port );
64
+ }
65
+
66
+ if ($ host = $ server ["HTTP_HOST " ] ?? null ) {
67
+ $ host = strtok ($ host , ": " );
68
+ $ uri = $ uri ->withHost ($ host );
69
+ }
70
+
71
+ if ($ query = $ server ["QUERY_STRING " ] ?? null ) {
72
+ $ uri = $ uri ->withQuery ($ query );
73
+ }
74
+
55
75
foreach ($ server as $ key => $ value ) {
56
76
if (str_starts_with ($ key , "HTTP_ " )) {
57
77
$ headerKey = substr ($ key , strlen ("HTTP_ " ));
Original file line number Diff line number Diff line change @@ -48,6 +48,22 @@ public function testCreateServerRequestFromGlobals_uri():void {
48
48
self ::assertEquals ("/path/to/somewhere " , $ request ->getUri ()->getPath ());
49
49
}
50
50
51
+ public function testCreateServerRequestFromGlobals_uri_withAllParts ():void {
52
+ $ sut = new RequestFactory ();
53
+ $ request = $ sut ->createServerRequestFromGlobalState ([
54
+ "REQUEST_METHOD " => "POST " ,
55
+ "REQUEST_URI " => "/path/to/somewhere/ " ,
56
+ "SERVER_PORT " => 8080 ,
57
+ "HTTP_HOST " => "localhost:8080 " ,
58
+ "QUERY_STRING " => "example=123 " ,
59
+ ], [], [], []);
60
+
61
+ self ::assertSame (
62
+ "http://localhost:8080/path/to/somewhere/?example=123 " ,
63
+ (string )$ request ->getUri ()
64
+ );
65
+ }
66
+
51
67
public function testCreateServerRequestFromGlobals_header ():void {
52
68
$ sut = new RequestFactory ();
53
69
$ request = $ sut ->createServerRequestFromGlobalState ([
You can’t perform that action at this time.
0 commit comments