From c3d173daeba8ae9d8087003f09dc7d24928fb120 Mon Sep 17 00:00:00 2001 From: Phil Bennett Date: Mon, 13 Aug 2018 11:52:32 +0100 Subject: [PATCH] Fix bug where content type header not being added to response on json strategy --- CHANGELOG.md | 5 +++++ docs/_config.yml | 2 +- docs/_data/releases.yml | 2 +- src/Strategy/JsonStrategy.php | 2 +- tests/Strategy/JsonStrategyTest.php | 7 +++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b699c60..76582b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [4.0.1] 2018-08 + +### Fixed +- Fixed a bug where content-type header would not be added to response in Json Strategy. + ## [4.0.0] 2018-08 ### Changed diff --git a/docs/_config.yml b/docs/_config.yml index a0bdc2a..a11ff0c 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -2,7 +2,7 @@ title: Route subtitle: The PHP League email: philipo@benito.email -description: Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute. +description: Fast PSR-7 routing and dispatch component including PSR-15 middleware, built on top of FastRoute. baseurl: # the subpath of your site, e.g. /blog url: # the base hostname & protocol for your site diff --git a/docs/_data/releases.yml b/docs/_data/releases.yml index 228743f..5db36d2 100644 --- a/docs/_data/releases.yml +++ b/docs/_data/releases.yml @@ -17,7 +17,7 @@ name: League\Route 4.x type: Current requires: PHP >= 7.1.0 - release: 4.0.0 - 2018-08 + release: 4.0.1 - 2018-08 support: Ongoing url: /4.x/ menu: diff --git a/src/Strategy/JsonStrategy.php b/src/Strategy/JsonStrategy.php index 0180a62..16f1c80 100644 --- a/src/Strategy/JsonStrategy.php +++ b/src/Strategy/JsonStrategy.php @@ -44,7 +44,7 @@ public function invokeRouteCallable(Route $route, ServerRequestInterface $reques } if ($response instanceof ResponseInterface && ! $response->hasHeader('content-type')) { - $response->withAddedHeader('content-type', 'application/json'); + $response = $response->withAddedHeader('content-type', 'application/json'); } return $response; diff --git a/tests/Strategy/JsonStrategyTest.php b/tests/Strategy/JsonStrategyTest.php index e86c555..e51f95d 100644 --- a/tests/Strategy/JsonStrategyTest.php +++ b/tests/Strategy/JsonStrategyTest.php @@ -50,6 +50,13 @@ function ( ->will($this->returnValue($expectedVars)) ; + $expectedResponse + ->expects($this->once()) + ->method('withAddedHeader') + ->with($this->equalTo('content-type'), $this->equalTo('application/json')) + ->will($this->returnSelf()) + ; + $factory = $this->createMock(ResponseFactoryInterface::class); $strategy = new JsonStrategy($factory);