PHPackages                             stadly/http - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. stadly/http

ActiveLibrary[HTTP &amp; Networking](/categories/http)

stadly/http
===========

A PHP library for handling HTTP headers.

v1.2.0(2y ago)1387↓100%1MITPHPPHP &gt;=8.0

Since Jul 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Stadly/Http)[ Packagist](https://packagist.org/packages/stadly/http)[ Docs](https://github.com/Stadly/Http)[ RSS](/packages/stadly-http/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (15)Used By (1)

Http
====

[](#http)

[![Latest Version on Packagist](https://camo.githubusercontent.com/db1cb087d9e09e7b7311ab9b3f313e75da70884e4486f22692316166f95177a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737461646c792f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stadly/http)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Coverage Status](https://camo.githubusercontent.com/09428475fc656c840e7333c7cc849deaedc3db0038ffba20edc4499ec1d9413e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f537461646c792f487474702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Stadly/Http/code-structure)[![Quality Score](https://camo.githubusercontent.com/4300e679874c5616d047399cee924f05557e630f6ab7f58013e7b97ae3754f48/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f537461646c792f487474702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Stadly/Http)[![Total Downloads](https://camo.githubusercontent.com/b9e1e01b2c9f7c0f933706ee8af4c12f3e00041b324a2cb13799df21fc6c82f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737461646c792f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stadly/http)

A PHP library for parsing and building HTTP headers.

Install
-------

[](#install)

Via Composer

```
$ composer require stadly/http
```

Usage
-----

[](#usage)

### Parsing HTTP headers

[](#parsing-http-headers)

Header values can be parsed using `fromValue` on each header class:

```
use Stadly\Http\Header\Common\ContentType;
use Stadly\Http\Header\Request\IfNoneMatch;
use Stadly\Http\Header\Response\ContentDisposition;

$contentType = ContentType::fromValue($_SERVER['HTTP_CONTENT_TYPE']);
$ifNoneMatch = IfNoneMatch::fromValue($_SERVER['HTTP_IF_NONE_MATCH']);
$contentDisposition = ContentDisposition::fromValue($_SERVER['HTTP_CONTENT_DISPOSITION']);
```

Header strings can be parsed using `HeaderFactory::fromString`:

```
use Stadly\Http\Header\Request\HeaderFactory as RequestHeaderFactory;
use Stadly\Http\Header\Response\HeaderFactory as ResponseHeaderFactory;

$requestHeaders = [
    'Content-Type: text/html; charset=UTF-8',
    'If-Match: "67ab43", "54ed21", W/"7892dd"',
    'Range: bytes=10-100, 200-300',
];
foreach ($requestHeaders as $headerString) {
    $header = RequestHeaderFactory::fromString($headerString);
}

$responseHeaders = [
    'Content-Type: multipart/form-data; boundary="abc def"',
    'Cache-Control: no-cache="foo, bar", max-age=120, must-revalidate',
    "Content-Disposition: attachment; filename=unicorn.jpg; filename*=UTF-8''%F0%9F%A6%84.jpg",
];
foreach ($responseHeaders as $headerString) {
    $header = ResponseHeaderFactory::fromString($headerString);
}
```

Note that header strings include the header name, while header values do not. The following results in identical headers:

```
use Stadly\Http\Header\Response\ContentDisposition;
use Stadly\Http\Header\Response\HeaderFactory;

$header1 = ContentDisposition::fromValue('inline; filename=image.jpg');
$header2 = HeaderFactory::fromString('Content-Disposition: inline; filename=image.jpg');
```

### Example usage

[](#example-usage)

Example parsing the `If-None-Match` request header and using it to determine whether to serve a file. The response headers `Content-Disposition` and `ETag` are built for serving the file.

```
use Stadly\Http\Header\Request\IfNoneMatch;
use Stadly\Http\Header\Response\ContentDisposition;
use Stadly\Http\Header\Response\ETag;
use Stadly\Http\Header\Value\EntityTag\EntityTag;

$entityTag = new EntityTag(md5($filename));
$ifNoneMatch = IfNoneMatch::fromValue($_SERVER['HTTP_IF_NONE_MATCH']);

if ($ifNoneMatch->evaluate($entityTag)) {
    // Serve file.
    $contentDisposition = new ContentDisposition('attachment');
    $contentDisposition->setFilename(basename($filename));
    header((string)$contentDisposition);

    $eTag = new ETag($entityTag);
    header((string)$eTag);

    readfile($filename);
} else {
    // 304 Not modified.
    http_response_code(304);
}
```

Header fields overview
----------------------

[](#header-fields-overview)

The checked header fields have been implemented.

### Common header fields

[](#common-header-fields)

#### Representation Metadata

[](#representation-metadata)

- Content-Type
- Content-Encoding
- Content-Language
- Content-Location

#### Payload Semantics

[](#payload-semantics)

- Content-Length
- Content-Range
- Trailer
- Transfer-Encoding

### Request header fields

[](#request-header-fields)

#### Controls

[](#controls)

- Cache-Control
- Expect
- Host
- Max-Forwards
- Pragma
- Range
- TE

#### Conditionals

[](#conditionals)

- If-Match
- If-None-Match
- If-Modified-Since
- If-Unmodified-Since
- If-Range

#### Content Negotiation

[](#content-negotiation)

- Accept
- Accept-Charset
- Accept-Encoding
- Accept-Language

#### Authentication Credentials

[](#authentication-credentials)

- Authorization
- Proxy-Authorization

#### Request Context

[](#request-context)

- From
- Referer
- User-Agent

### Response header fields

[](#response-header-fields)

#### Control Data

[](#control-data)

- Age
- Cache-Control
- Expires
- Date
- Location
- Retry-After
- Vary
- Warning

#### Validator Header Fields

[](#validator-header-fields)

- ETag
- Last-Modified

#### Authentication Challenges

[](#authentication-challenges)

- WWW-Authenticate
- Proxy-Authenticate

#### Response Context

[](#response-context)

- Accept-Ranges
- Allow
- Server

#### Other

[](#other)

- Content-Disposition

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Magnar Ovedal Myrtveit](https://github.com/Stadly)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~145 days

Recently: every ~188 days

Total

14

Last Release

961d ago

Major Versions

v0.8.0 → v1.0.02021-09-02

PHP version history (4 changes)v0.1.0PHP ^7.1

v0.7.0PHP &gt;=7.3

v0.8.0PHP &gt;=7.4

v1.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f5d9e0c770d26a4a636b51657f9f89b076bb401e8f16b2f7aac9dfa1341f6d69?d=identicon)[Stadly](/maintainers/Stadly)

---

Top Contributors

[![Stadly](https://avatars.githubusercontent.com/u/7263579?v=4)](https://github.com/Stadly "Stadly (131 commits)")

---

Tags

httpresponserequestphpheaderEtagcontent-typerangemedia typeif-matchif-none-matchEntity TagStadlybyte-ranges-specifierHTTP-dateother-ranges-specifier

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stadly-http/health.svg)

```
[![Health](https://phpackages.com/badges/stadly-http/health.svg)](https://phpackages.com/packages/stadly-http)
```

PHPackages © 2026

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