Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Aug 21, 2024
2 parents 5b3d39c + d308022 commit 5a3d177
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

## [4.2.0] - 2024-08-21

### Added

- Response classes now have a `withoutHeaders()` method to remove headers from the response.

### Fixed

- [#18](https://github.com/laravel-json-api/core/pull/18) Ensure headers are merged when using the `withHeaders()`
method on the JSON:API response classes. This was previously not merging headers, which was not correct and therefore
this is a bug fix. If you were relying on this behaviour, use the new `withoutHeaders()` method to remove any headers.

## [4.1.0] - 2024-06-26

### Fixed
Expand Down
19 changes: 17 additions & 2 deletions src/Core/Responses/Concerns/IsResponsable.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,22 @@ public function withHeader(string $name, string $value = null): self
*/
public function withHeaders(array $headers): self
{
$this->headers = $headers;
$this->headers = array_merge($this->headers, $headers);

return $this;
}

/**
* Remove response headers.
*
* @param string ...$headers
* @return $this
*/
public function withoutHeaders(string ...$headers): self
{
foreach ($headers as $header) {
unset($this->headers[$header]);
}

return $this;
}
Expand All @@ -170,7 +185,7 @@ protected function headers(): array
{
return array_merge(
['Content-Type' => 'application/vnd.api+json'],
$this->headers ?: [],
$this->headers,
);
}

Expand Down

0 comments on commit 5a3d177

Please sign in to comment.