Skip to content

Commit

Permalink
feat: add method to remove headers from response classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Aug 21, 2024
1 parent e96381f commit 249ee96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

### 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
18 changes: 16 additions & 2 deletions src/Core/Responses/Concerns/IsResponsable.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public function withHeader(string $name, string $value = null): self
* Set response headers.
*
* @param array $headers
* @param bool $merge
* @return $this
*/
public function withHeaders(array $headers): self
Expand All @@ -164,14 +163,29 @@ public function withHeaders(array $headers): self
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;
}

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

Expand Down

0 comments on commit 249ee96

Please sign in to comment.