Skip to content

Commit 9901e0f

Browse files
mabardg
authored andcommitted
RequestFactory: set user and password to Url (#161)
1 parent baac1bb commit 9901e0f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Http/RequestFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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());

0 commit comments

Comments
 (0)