Skip to content

Commit 5a3d177

Browse files
committed
Merge branch 'release/4.2.0'
2 parents 5b3d39c + d308022 commit 5a3d177

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. This projec
55

66
## Unreleased
77

8+
## [4.2.0] - 2024-08-21
9+
10+
### Added
11+
12+
- Response classes now have a `withoutHeaders()` method to remove headers from the response.
13+
14+
### Fixed
15+
16+
- [#18](https://github.com/laravel-json-api/core/pull/18) Ensure headers are merged when using the `withHeaders()`
17+
method on the JSON:API response classes. This was previously not merging headers, which was not correct and therefore
18+
this is a bug fix. If you were relying on this behaviour, use the new `withoutHeaders()` method to remove any headers.
19+
820
## [4.1.0] - 2024-06-26
921

1022
### Fixed

src/Core/Responses/Concerns/IsResponsable.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,22 @@ public function withHeader(string $name, string $value = null): self
158158
*/
159159
public function withHeaders(array $headers): self
160160
{
161-
$this->headers = $headers;
161+
$this->headers = array_merge($this->headers, $headers);
162+
163+
return $this;
164+
}
165+
166+
/**
167+
* Remove response headers.
168+
*
169+
* @param string ...$headers
170+
* @return $this
171+
*/
172+
public function withoutHeaders(string ...$headers): self
173+
{
174+
foreach ($headers as $header) {
175+
unset($this->headers[$header]);
176+
}
162177

163178
return $this;
164179
}
@@ -170,7 +185,7 @@ protected function headers(): array
170185
{
171186
return array_merge(
172187
['Content-Type' => 'application/vnd.api+json'],
173-
$this->headers ?: [],
188+
$this->headers,
174189
);
175190
}
176191

0 commit comments

Comments
 (0)