Skip to content

Commit

Permalink
Fix bug where content type header not being added to response on json…
Browse files Browse the repository at this point in the history
… strategy
  • Loading branch information
philipobenito committed Aug 13, 2018
1 parent c471aa6 commit c3d173d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/_data/releases.yml
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/JsonStrategy.php
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/Strategy/JsonStrategyTest.php
Expand Up @@ -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);
Expand Down

0 comments on commit c3d173d

Please sign in to comment.