File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,36 @@ public function getScriptName():string {
136136 * The URI which was given in order to access this page.
137137 */
138138 public function getRequestUri ():UriInterface {
139- return new Uri ($ this ->server ["REQUEST_URI " ]);
139+ $ uri = new Uri ();
140+
141+ if (isset ($ this ->server ["HTTPS " ])) {
142+ $ uri = $ uri ->withScheme ("https " );
143+ }
144+ else {
145+ $ uri = $ uri ->withScheme ("http " );
146+ }
147+
148+ if (isset ($ this ->server ["HTTP_HOST " ])) {
149+ $ uri = $ uri ->withHost (
150+ strtok ($ this ->server ["HTTP_HOST " ], ": " )
151+ );
152+ }
153+
154+ if (isset ($ this ->server ["SERVER_PORT " ])) {
155+ $ uri = $ uri ->withPort ((int )$ this ->server ["SERVER_PORT " ]);
156+ }
157+
158+ if (isset ($ this ->server ["REQUEST_URI " ])) {
159+ $ uri = $ uri ->withPath (
160+ strtok ($ this ->server ["REQUEST_URI " ], "? " )
161+ );
162+ }
163+
164+ if (isset ($ this ->server ["QUERY_STRING " ])) {
165+ $ uri = $ uri ->withQuery ($ this ->server ["QUERY_STRING " ]);
166+ }
167+
168+ return $ uri ;
140169 }
141170
142171 public function getFullUri ():UriInterface {
Original file line number Diff line number Diff line change @@ -117,7 +117,11 @@ public function testGetScriptName() {
117117
118118 public function testGetRequestUri () {
119119 $ sut = new ServerInfo (self ::getServerArray ());
120- self ::assertEquals ("/example?key1=value1&key2=value2 " , $ sut ->getRequestUri ());
120+
121+ self ::assertEquals (
122+ "http://localhost/example?key1=value1&key2=value2 " ,
123+ $ sut ->getRequestUri ()
124+ );
121125 }
122126
123127 public function testNullFields () {
You can’t perform that action at this time.
0 commit comments