File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 3333 * - **secure** - Connection is secure
3434 * - **accept** - HTTP accept parameters
3535 * - **proxy_ip** - Proxy IP address of the client
36+ * - **host** - The hostname from the request.
37+ * - **servername** - The server's hostname. See `$_SERVER['SERVER_NAME']`.
3638 */
3739class Request
3840{
@@ -126,6 +128,15 @@ class Request
126128 */
127129 public string $ host ;
128130
131+ /**
132+ * Server name
133+ *
134+ * CAUTION: Note: Under Apache 2, UseCanonicalName = On and ServerName must be set.
135+ * Otherwise, this value reflects the hostname supplied by the client, which can be spoofed.
136+ * It is not safe to rely on this value in security-dependent contexts.
137+ */
138+ public string $ servername ;
139+
129140 /**
130141 * Stream path for where to pull the request body from
131142 */
@@ -164,6 +175,7 @@ public function __construct(array $config = [])
164175 'accept ' => self ::getVar ('HTTP_ACCEPT ' ),
165176 'proxy_ip ' => self ::getProxyIpAddress (),
166177 'host ' => self ::getVar ('HTTP_HOST ' ),
178+ 'servername ' => self ::getVar ('SERVER_NAME ' , '' ),
167179 ];
168180 }
169181
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ protected function setUp(): void
2323 $ _SERVER ['REMOTE_ADDR ' ] = '8.8.8.8 ' ;
2424 $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = '32.32.32.32 ' ;
2525 $ _SERVER ['HTTP_HOST ' ] = 'example.com ' ;
26+ $ _SERVER ['SERVER_NAME ' ] = 'test.com ' ;
2627 $ _SERVER ['CONTENT_TYPE ' ] = '' ;
2728
2829 $ _GET = [];
@@ -52,6 +53,7 @@ public function testDefaults(): void
5253 $ this ->assertFalse ($ this ->request ->secure );
5354 $ this ->assertEquals ('' , $ this ->request ->accept );
5455 $ this ->assertEquals ('example.com ' , $ this ->request ->host );
56+ $ this ->assertEquals ('test.com ' , $ this ->request ->servername );
5557 }
5658
5759 public function testIpAddress (): void
You can’t perform that action at this time.
0 commit comments