Skip to content

Commit

Permalink
Exclude charset from response content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Mar 8, 2024
1 parent a1b8247 commit 349951d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Validation/ResponseValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ protected function response(): Response

protected function contentType(): ?string
{
return $this->response->headers->get('Content-Type');
return $this->response->headers->get('Content-Type') !== null
? Str::before($this->response->headers->get('Content-Type'), ';')
: null;
}

protected function schemaType(Schema $schema): ?string
Expand Down
17 changes: 17 additions & 0 deletions tests/ResponseValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ public function test_validates_valid_problem_json_response()
->assertValidResponse(422);
}

public function test_validates_valid_response_with_charset()
{
Route::get('/users', function () {
return response()->json([
[
'id' => 1,
'name' => 'Jim',
'email' => '[email protected]',
],
], 422, ['Content-Type' => 'application/json; charset=utf-8']);
})->middleware(Middleware::class);

$this->getJson('/users')
->assertValidRequest()
->assertValidResponse(422);
}

public function test_validates_invalid_content_type(): void
{
Route::get('/users', static function () {
Expand Down

0 comments on commit 349951d

Please sign in to comment.