https://github.com/dotkernel/dot-response-header
Configuration of all Response Headers
https://github.com/dotkernel/dot-response-header
Last synced: 7 months ago
JSON representation
Configuration of all Response Headers
- Host: GitHub
- URL: https://github.com/dotkernel/dot-response-header
- Owner: dotkernel
- License: mit
- Created: 2021-05-04T09:19:20.000Z (over 4 years ago)
- Default Branch: 3.0
- Last Pushed: 2025-03-12T08:12:40.000Z (9 months ago)
- Last Synced: 2025-04-15T01:03:01.578Z (8 months ago)
- Language: PHP
- Homepage: https://docs.dotkernel.org/dot-response-header/
- Size: 92.8 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# dot-response-header
`dot-response-header` is Dotkernel's middleware for setting and overwriting custom response headers.
## Documentation
Documentation is available at: https://docs.dotkernel.org/dot-response-header/.
## Badges


[](https://github.com/dotkernel/dot-response-header/issues)
[](https://github.com/dotkernel/dot-response-header/network)
[](https://github.com/dotkernel/dot-response-header/stargazers)
[](https://github.com/dotkernel/dot-response-header/blob/3.0/LICENSE)
[](https://github.com/dotkernel/dot-response-header/actions/workflows/continuous-integration.yml)
[](https://codecov.io/gh/dotkernel/dot-response-header)
[](https://github.com/dotkernel/dot-response-header/actions/workflows/static-analysis.yml)
## Requirements
- **PHP**: 8.1, 8.2, 8.3 or 8.4
## Installation
Run the following command in your project root directory:
```shell
composer require dotkernel/dot-response-header
```
Next, register the package's `ConfigProvider` to your application config.
```php
Dot\ResponseHeader\ConfigProvider::class,
```
> Make sure to register the package under the `// DK packages` section.
After registering the package, add it to the middleware stack in `config/pipeline.php` after `$app->pipe(RouteMiddleware::class);`
```php
$app->pipe(RouteMiddleware::class);
$app->pipe(\Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware::class);
```
Create a new file `response-header.global.php` in `config/autoload` with the below configuration array:
```php
[
'*' => [
'CustomHeader1' => [
'value' => 'CustomHeader1-Value',
'overwrite' => true,
],
'CustomHeader2' => [
'value' => 'CustomHeader2-Value',
'overwrite' => false,
],
],
'home' => [
'CustomHeader' => [
'value' => 'header3',
]
],
'login' => [
'LoginHeader' => [
'value' => 'LoginHeader-Value',
'overwrite' => false
]
],
]
];
```
Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the `*` key.
All headers under `*` will be set for every response.
To add response headers for a specific set of routes, define a new array using the route name as the array key.
Example:
```php
'dot_response_headers' => [
'user' => [
'UserCustomHeader' => [
'value' => 'UserCustomHeader-Value',
'overwrite' => false
]
],
]
// This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user'
```
To overwrite an existing header use `overwrite => true`.