From c4e4223c952f62765071edfe8548ed98c2656a0a Mon Sep 17 00:00:00 2001 From: Arnold Daniels Date: Wed, 28 Dec 2016 23:34:13 +0100 Subject: [PATCH] Set protocol version for response in middleware --- src/Auth/Middleware.php | 4 +++- tests/Auth/MiddlewareTest.php | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 @@ protected function forbidden(ServerRequestInterface $request, ResponseInterface { $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 @@ public function testInvokeUnauthorized() $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 @@ public function testInvokeUnauthorized() $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 @@ public function testInvokeForbidden() $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 @@ public function testInvokeForbidden() $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());