File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ public function createHttpRequest(): Request
6565 $ url = new Url ;
6666 $ this ->getServer ($ url );
6767 $ this ->getPathAndQuery ($ url );
68+ $ this ->getUserAndPassword ($ url );
6869 [$ post , $ cookies ] = $ this ->getGetPostCookie ($ url );
6970 [$ remoteAddr , $ remoteHost ] = $ this ->getClient ($ url );
7071
@@ -116,6 +117,13 @@ private function getPathAndQuery(Url $url): void
116117 }
117118
118119
120+ private function getUserAndPassword (Url $ url ): void
121+ {
122+ $ url ->setUser ($ _SERVER ['PHP_AUTH_USER ' ] ?? '' );
123+ $ url ->setPassword ($ _SERVER ['PHP_AUTH_PW ' ] ?? '' );
124+ }
125+
126+
119127 private function getScriptPath (Url $ url ): string
120128 {
121129 $ path = $ url ->getPath ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Test: Nette\Http\RequestFactory and user and password.
5+ */
6+
7+ declare (strict_types=1 );
8+
9+ use Nette \Http \RequestFactory ;
10+ use Tester \Assert ;
11+
12+
13+ require __DIR__ . '/../bootstrap.php ' ;
14+
15+
16+ $ _SERVER = [
17+ 'PHP_AUTH_USER ' => 'user ' ,
18+ 'PHP_AUTH_PW ' => 'password ' ,
19+ ];
20+ $ factory = new RequestFactory ;
21+ Assert::same ('user ' , $ factory ->createHttpRequest ()->getUrl ()->getUser ());
22+ Assert::same ('password ' , $ factory ->createHttpRequest ()->getUrl ()->getPassword ());
23+
24+
25+ $ _SERVER = [];
26+ $ factory = new RequestFactory ;
27+ Assert::same ('' , $ factory ->createHttpRequest ()->getUrl ()->getUser ());
28+ Assert::same ('' , $ factory ->createHttpRequest ()->getUrl ()->getPassword ());
You can’t perform that action at this time.
0 commit comments