Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
As per specification, the server should allow using the Accept head…
…er in requests.

Added test for `Accept` header and added header to the middleware check.

Fixes issue #12
  • Loading branch information
bbrala committed Oct 25, 2018
commit bdec0e3c1a2b2d83bafba8366579d2858c0a9357
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

- Fix inconsistent url in `authentication_test.stub` (issue #8)
- Route stub generated a route with the controller action `destroy` instead of `delete` (issue #9)
- As per specification, the server should allow using the `Accept` header in requests. (issue #12)

## 0.3.0

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/InspectContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InspectContentType
*/
public function handle(Request $request, Closure $next)
{
if ('application/vnd.api+json' !== $request->header('Content-Type')) {
if ('application/vnd.api+json' !== $request->header('Content-Type') && 'application/vnd.api+json' !== $request->header('Accept')) {
throw new ContentTypeNotSupportedException('Your request should be in json api format. (Content-Type: application/vnd.api+json)');
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/InspectContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ public function itDoesNotThrowContentTypeNotSupportedException()
});
$this->assertEquals($response, null);
}

/**
* @test
*
* @throws ContentTypeNotSupportedException
*/
public function itDoesNotThrowNotSupportedExceptionWhenUsingAcceptHeader()
{
$this->request->headers->set('Accept', 'application/vnd.api+json');
$response = $this->middleware->handle($this->request, function () {
});
$this->assertEquals($response, null);
}
}