PHPackages                             wyrihaximus/react-http-middleware-with-headers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wyrihaximus/react-http-middleware-with-headers

ActiveLibrary

wyrihaximus/react-http-middleware-with-headers
==============================================

react/http middleware to add headers to a response

3.0.0(1y ago)29.0k[1 issues](https://github.com/WyriHaximus/reactphp-http-middleware-with-headers/issues)[5 PRs](https://github.com/WyriHaximus/reactphp-http-middleware-with-headers/pulls)MITPHPPHP ^8.2CI failing

Since Dec 13Pushed 1w ago2 watchersCompare

[ Source](https://github.com/WyriHaximus/reactphp-http-middleware-with-headers)[ Packagist](https://packagist.org/packages/wyrihaximus/react-http-middleware-with-headers)[ GitHub Sponsors](https://github.com/WyriHaximus)[ RSS](/packages/wyrihaximus-react-http-middleware-with-headers/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (5)Versions (12)Used By (0)

Add headers to responses
========================

[](#add-headers-to-responses)

[![Build Status](https://camo.githubusercontent.com/62e007b791ed945204580fb333fc023affdaa5eeb83debbecfca2a9568a2c6e4/68747470733a2f2f7472617669732d63692e6f72672f57797269486178696d75732f72656163747068702d687474702d6d6964646c65776172652d776974682d686561646572732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/WyriHaximus/reactphp-http-middleware-with-headers)[![Latest Stable Version](https://camo.githubusercontent.com/5f0adc71a4512e7fca81097f7e8dd50bb381af4f3149f51cfd93e36e804496b5/68747470733a2f2f706f7365722e707567782e6f72672f57797269486178696d75732f72656163742d687474702d6d6964646c65776172652d776974682d686561646572732f762f737461626c652e706e67)](https://packagist.org/packages/WyriHaximus/react-http-middleware-with-headers)[![Total Downloads](https://camo.githubusercontent.com/8ecea7883c52c1b62720326d1edb0375b2a61031c5538fac94a9c7c0a3fa6461/68747470733a2f2f706f7365722e707567782e6f72672f57797269486178696d75732f72656163742d687474702d6d6964646c65776172652d776974682d686561646572732f646f776e6c6f6164732e706e67)](https://packagist.org/packages/WyriHaximus/react-http-middleware-with-headers)[![Code Coverage](https://camo.githubusercontent.com/0e83b88cb625200d9759d88bccd31cb6ffc6f16e75f1b32f5fcb00a9fc8aa208/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f57797269486178696d75732f72656163747068702d687474702d6d6964646c65776172652d776974682d686561646572732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/WyriHaximus/reactphp-http-middleware-with-headers/?branch=master)[![License](https://camo.githubusercontent.com/f19aac75881994a3f8096702f401a1b1854d7e8459ade033bfe24af45cc77c7a/68747470733a2f2f706f7365722e707567782e6f72672f57797269486178696d75732f72656163742d687474702d6d6964646c65776172652d776974682d686561646572732f6c6963656e73652e706e67)](https://packagist.org/packages/WyriHaximus/react-http-middleware-with-headers)

Install
=======

[](#install)

To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.

```
composer require wyrihaximus/react-http-middleware-with-headers

```

This middleware adds all the headers passed into the constructor to the responses flowing through this middleware.

Usage
=====

[](#usage)

```
use React\Http\HttpServer;
use WyriHaximus\React\Http\Middleware\Header;
use WyriHaximus\React\Http\Middleware\WithHeadersMiddleware;
use WyriHaximus\React\Http\Middleware\WithRandomHeadersMiddleware;

$server = new HttpServer([
    /** Other middleware */
    new WithHeadersMiddleware(
        'X-Powered-By' => 'wyrihaximus.net (11.0.33)',
    ),
    new WithRandomHeadersMiddleware(
        1, // Minimum header count to attach
        2,  // Maximum header count to attach
        new Header('X-nanananana', 'Batcache'),
        new Header('X-Horde', 'For the Horde!'),
        new Header('X-Picard', 'Make it so'),
    ),
    /** Other middleware */
]);
```

Combined with [`wyrihaximus-net/x-headers`](https://github.com/WyriHaximusNet/php-x-headers) you'll get an ever-growing set of Nerdy headers:

```
use React\Http\HttpServer;
use WyriHaximus\React\Http\Middleware\Headers;
use WyriHaximus\React\Http\Middleware\WithRandomHeadersMiddleware;
use WyriHaximusNet\XHeaders;

$server = new HttpServer([
    /** Other middleware */
    new WithRandomHeadersMiddleware(
        1,
        ceil(count(XHeaders\Headers::HEADERS) / 4), // Add up to 25% of the list to it
        ...Headers::fromIterable(XHeaders\Headers::HEADERS),
    ),
    /** Other middleware */
]);
```

This uses the `Headers` helper that can transform key value iterables like the following to an iterable with `Header` objects:

```
[
    'X-Header' => 'contents',
]
```

License
=======

[](#license)

The MIT License (MIT)

Copyright (c) 2024 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

48

↑

FairBetter than 94% of packages

Maintenance60

Regular maintenance activity

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 52.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1228 days

Total

3

Last Release

617d ago

Major Versions

1.0.0 → 2.0.02020-07-11

2.0.0 → 3.0.02024-09-04

PHP version history (3 changes)1.0.0PHP ^7.0

2.0.0PHP ^7.4

3.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

---

Top Contributors

[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (41 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (11 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (7 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (1 commits)")

---

Tags

hacktoberfestphpreactphp

### Embed Badge

![Health badge](/badges/wyrihaximus-react-http-middleware-with-headers/health.svg)

```
[![Health](https://phpackages.com/badges/wyrihaximus-react-http-middleware-with-headers/health.svg)](https://phpackages.com/packages/wyrihaximus-react-http-middleware-with-headers)
```

###  Alternatives

[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[iwechatpay/openapi

为 wechatpay/wechatpay 增加IDE提示的接口描述包。

406.7k](/packages/iwechatpay-openapi)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
