Skip to content

Commit 249ee96

Browse files
committed
feat: add method to remove headers from response classes
1 parent e96381f commit 249ee96

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

CHANGELOG.md

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

66
## Unreleased
77

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

1020
### Fixed

src/Core/Responses/Concerns/IsResponsable.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public function withHeader(string $name, string $value = null): self
154154
* Set response headers.
155155
*
156156
* @param array $headers
157-
* @param bool $merge
158157
* @return $this
159158
*/
160159
public function withHeaders(array $headers): self
@@ -164,14 +163,29 @@ public function withHeaders(array $headers): self
164163
return $this;
165164
}
166165

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+
}
177+
178+
return $this;
179+
}
180+
167181
/**
168182
* @return array
169183
*/
170184
protected function headers(): array
171185
{
172186
return array_merge(
173187
['Content-Type' => 'application/vnd.api+json'],
174-
$this->headers ?: [],
188+
$this->headers,
175189
);
176190
}
177191

0 commit comments

Comments
 (0)