From 16eadf280de86de4615347af2ee7a36f35efc8ca Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 16 Jan 2019 20:29:06 -0800 Subject: Fix headers in _SERVER (laravel integration fix) --- src/PSR7Client.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/PSR7Client.php b/src/PSR7Client.php index 1136ce10..d8ec4405 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -146,9 +146,13 @@ class PSR7Client $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; - $server['HTTP_USER_AGENT'] = ''; - if (isset($ctx['headers']['User-Agent'][0])) { - $server['HTTP_USER_AGENT'] = $ctx['headers']['User-Agent'][0]; + foreach ($ctx['headers'] as $key => $value) { + $key = strtoupper(str_replace('-', '_', $key)); + if (\in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) { + $_SERVER[$key] = implode(', ', $value); + } else { + $_SERVER['HTTP_' . $key] = implode(', ', $value); + } } return $server; -- cgit v1.2.3 From bcb4b7d1f0c5ef4e13aac493611cd28fdde45a29 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 16 Jan 2019 21:15:39 -0800 Subject: Fix variable name --- src/PSR7Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/PSR7Client.php b/src/PSR7Client.php index d8ec4405..d034a102 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -149,9 +149,9 @@ class PSR7Client foreach ($ctx['headers'] as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); if (\in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) { - $_SERVER[$key] = implode(', ', $value); + $server[$key] = implode(', ', $value); } else { - $_SERVER['HTTP_' . $key] = implode(', ', $value); + $server['HTTP_' . $key] = implode(', ', $value); } } -- cgit v1.2.3 From effd1cd2922ca4faabb60f02870a8e40130db329 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 16 Jan 2019 21:24:46 -0800 Subject: Add default empty User Agent --- src/PSR7Client.php | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/PSR7Client.php b/src/PSR7Client.php index d034a102..e0be34a2 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -146,6 +146,7 @@ class PSR7Client $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; + $server['HTTP_USER_AGENT'] = ''; foreach ($ctx['headers'] as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); if (\in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) { -- cgit v1.2.3 From 76481e3e0cc83bc7ef843b8ee5cb6bbe02f4bd9c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Jan 2019 01:12:16 -0800 Subject: Try to fix $_SERVER data between requests --- src/PSR7Client.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/PSR7Client.php b/src/PSR7Client.php index e0be34a2..350637e2 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -32,6 +32,8 @@ class PSR7Client /*** @var UploadedFileFactoryInterface */ private $uploadsFactory; + private $originalServer = []; + /** @var array Valid values for HTTP protocol version */ private static $allowedVersions = ['1.0', '1.1', '2',]; @@ -51,6 +53,7 @@ class PSR7Client $this->requestFactory = $requestFactory ?? new Diactoros\ServerRequestFactory(); $this->streamFactory = $streamFactory ?? new Diactoros\StreamFactory(); $this->uploadsFactory = $uploadsFactory ?? new Diactoros\UploadedFileFactory(); + $this->originalServer = $_SERVER; } /** @@ -129,6 +132,8 @@ class PSR7Client $response->getBody()->__toString(), json_encode(['status' => $response->getStatusCode(), 'headers' => $headers]) ); + + $_SERVER = $this->originalServer; } /** @@ -140,7 +145,7 @@ class PSR7Client */ protected function configureServer(array $ctx): array { - $server = $_SERVER; + $server = $this->originalServer; $server['REQUEST_TIME'] = time(); $server['REQUEST_TIME_FLOAT'] = microtime(true); $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; -- cgit v1.2.3