summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2016-12-28 23:34:13 +0100
committerArnold Daniels <arnold@jasny.net>2016-12-28 23:34:13 +0100
commitc4e4223c952f62765071edfe8548ed98c2656a0a (patch)
tree5139eb56923dcb8910f4902cf08d7315fc315d47
parent233a9aeb56144244092ac8270ede99342d9be616 (diff)
downloadauth-c4e4223c952f62765071edfe8548ed98c2656a0a.zip
auth-c4e4223c952f62765071edfe8548ed98c2656a0a.tar.gz
auth-c4e4223c952f62765071edfe8548ed98c2656a0a.tar.bz2
Set protocol version for response in middlewarev1.0.0
-rw-r--r--src/Auth/Middleware.php4
-rw-r--r--tests/Auth/MiddlewareTest.php4
2 files changed, 7 insertions, 1 deletions
diff --git a/src/Auth/Middleware.php b/src/Auth/Middleware.php
index 248feac..2e06789 100644
--- a/src/Auth/Middleware.php
+++ b/src/Auth/Middleware.php
@@ -76,7 +76,9 @@ class Middleware
{
$unauthorized = $this->auth->user() === null;
- $forbiddenResponse = $response->withStatus($unauthorized ? 401 : 403);
+ $forbiddenResponse = $response
+ ->withProtocolVersion($request->getProtocolVersion())
+ ->withStatus($unauthorized ? 401 : 403);
$forbiddenResponse->getBody()->write('Access denied');
return $forbiddenResponse;
diff --git a/tests/Auth/MiddlewareTest.php b/tests/Auth/MiddlewareTest.php
index bba5357..84da021 100644
--- a/tests/Auth/MiddlewareTest.php
+++ b/tests/Auth/MiddlewareTest.php
@@ -153,6 +153,7 @@ class MiddlewareTest extends TestCase
$request = $this->createMock(ServerRequestInterface::class);
$request->expects($this->once())->method('getAttribute')->with('auth')->willReturn('user');
+ $request->expects($this->once())->method('getProtocolVersion')->willReturn('1.1');
$stream = $this->createMock(StreamInterface::class);
$stream->expects($this->once())->method('write')->with('Access denied');
@@ -161,6 +162,7 @@ class MiddlewareTest extends TestCase
$forbiddenResponse->expects($this->once())->method('getBody')->willReturn($stream);
$response = $this->createMock(ResponseInterface::class);
+ $response->expects($this->once())->method('withProtocolVersion')->with('1.1')->willReturnSelf();
$response->expects($this->once())->method('withStatus')->with(401)->willReturn($forbiddenResponse);
$next = $this->createCallbackMock($this->never());
@@ -179,6 +181,7 @@ class MiddlewareTest extends TestCase
$request = $this->createMock(ServerRequestInterface::class);
$request->expects($this->once())->method('getAttribute')->with('auth')->willReturn('user');
+ $request->expects($this->once())->method('getProtocolVersion')->willReturn('1.1');
$stream = $this->createMock(StreamInterface::class);
$stream->expects($this->once())->method('write')->with('Access denied');
@@ -187,6 +190,7 @@ class MiddlewareTest extends TestCase
$forbiddenResponse->expects($this->once())->method('getBody')->willReturn($stream);
$response = $this->createMock(ResponseInterface::class);
+ $response->expects($this->once())->method('withProtocolVersion')->with('1.1')->willReturnSelf();
$response->expects($this->once())->method('withStatus')->with(403)->willReturn($forbiddenResponse);
$next = $this->createCallbackMock($this->never());