Skip to content

Commit

Permalink
release v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Mar 7, 2020
1 parent 275854c commit 308eff5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ vendor
composer.lock
coverage
*.cache
.idea
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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/).

## [2.0.1] - 2020-03-07
### Fixed
- If no Accept header field is present, returns the default format instead a `406` response, according to the specs [#6], [#8]

## [2.0.0] - 2019-11-29
### Added
- The array of formats passed to `ContentType` middleware can contain plain values, for example `new Middlewares\ContentType(['html', 'json'])`, so it's not required to provide the full data for each format (the list of headers, extensions, etc).
Expand Down Expand Up @@ -83,6 +87,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## 0.1.0 - 2016-10-01
First version

[#6]: https://github.com/middlewares/negotiation/issues/6
[#8]: https://github.com/middlewares/negotiation/issues/8

[2.0.1]: https://github.com/middlewares/negotiation/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/middlewares/negotiation/compare/v1.1.0...v2.0.0
[1.1.0]: https://github.com/middlewares/negotiation/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/middlewares/negotiation/compare/v0.5.0...v1.0.0
Expand Down
30 changes: 30 additions & 0 deletions tests/ContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,34 @@ public function testCharset(array $charsets, string $accept, string $acceptChars

$this->assertEquals($result, $response->getHeaderLine('Content-Type'));
}

public function testMissingHeader()
{
$request = Factory::createServerRequest('GET', '/');

$response = Dispatcher::run([
(new ContentType(['json', 'html']))->errorResponse(),
function ($request) {
echo $request->getHeaderLine('Accept');
},
], $request);

$this->assertEquals('application/json', (string) $response->getBody());
$this->assertEquals('application/json; charset=UTF-8', $response->getHeaderLine('Content-Type'));
}

public function testNotMissingHeader()
{
$request = Factory::createServerRequest('GET', '/')->withHeader('Accept', 'image/*');

$response = Dispatcher::run([
(new ContentType(['json', 'html']))->errorResponse(),
function ($request) {
echo $request->getHeaderLine('Accept');
},
], $request);

$this->assertEquals('', $response->getHeaderLine('Content-Type'));
$this->assertEquals(406, $response->getStatusCode());
}
}

0 comments on commit 308eff5

Please sign in to comment.