PHPackages                             corpus/http-message-utils - 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. corpus/http-message-utils

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

corpus/http-message-utils
=========================

Utilities for working with Psr7 Http Messages

v0.6.0(5mo ago)152.5k↑77.6%[2 PRs](https://github.com/CorpusPHP/HttpMessageUtils/pulls)MITPHPPHP &gt;=7.3CI passing

Since Mar 26Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/CorpusPHP/HttpMessageUtils)[ Packagist](https://packagist.org/packages/corpus/http-message-utils)[ RSS](/packages/corpus-http-message-utils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (10)Versions (14)Used By (0)

HTTP Message Utils
==================

[](#http-message-utils)

[![Latest Stable Version](https://camo.githubusercontent.com/21f061b098a24607c04435b569d34388357b695c2bb244cf369df1e3f9c4ccad/68747470733a2f2f706f7365722e707567782e6f72672f636f727075732f687474702d6d6573736167652d7574696c732f76657273696f6e)](https://packagist.org/packages/corpus/http-message-utils)[![License](https://camo.githubusercontent.com/e731ca47c36de5b4baed5997fdc6b61fb187ccb53d1681cf79d22e056fcb4482/68747470733a2f2f706f7365722e707567782e6f72672f636f727075732f687474702d6d6573736167652d7574696c732f6c6963656e7365)](https://packagist.org/packages/corpus/http-message-utils)[![ci.yml](https://github.com/CorpusPHP/HttpMessageUtils/actions/workflows/ci.yml/badge.svg)](https://github.com/CorpusPHP/HttpMessageUtils/actions/workflows/ci.yml)

Utilities for working with [PSR-7 Http Message](https://www.php-fig.org/psr/psr-7/) objects.

Requirements
------------

[](#requirements)

- **psr/http-message**: ^1 || ^2
- **php**: &gt;=7.3

Installing
----------

[](#installing)

Install the latest version with:

```
composer require 'corpus/http-message-utils'
```

Documentation
-------------

[](#documentation)

### Class: Corpus\\HttpMessageUtils\\Authorization\\AuthorizationHeaderParser

[](#class-corpushttpmessageutilsauthorizationauthorizationheaderparser)

Utility to split an Authorization header into `` and `` ala: `Authorization:  `

The parser itself is authorization type agnostic and works with any RFC7235 conforming authorization type.

### Example:

[](#example)

```
$serverRequest = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
$parsedAuth    = (new \Corpus\HttpMessageUtils\Authorization\AuthorizationHeaderParser)->parseServerRequest($serverRequest);

if( $parsedAuth ) {
    echo 'type: ' . $parsedAuth->getType();
    echo 'cred: ' . $parsedAuth->getCredentials();
}
```

#### Method: AuthorizationHeaderParser-&gt;\_\_construct

[](#method-authorizationheaderparser-__construct)

```
function __construct([ ?\Corpus\HttpMessageUtils\Authorization\AuthorizationPartsFactory $factory = null])
```

##### Parameters:

[](#parameters)

- ***\\Corpus\\HttpMessageUtils\\Authorization\\AuthorizationPartsFactory*** | ***null*** `$factory` - Optional factory for construction of result objects

---

#### Method: AuthorizationHeaderParser-&gt;parseString

[](#method-authorizationheaderparser-parsestring)

```
function parseString(string $headerValue) : ?\Corpus\HttpMessageUtils\Authorization\AuthorizationPartsInterface
```

Parses an Authorization header into `` and ``

##### Parameters:

[](#parameters-1)

- ***string*** `$headerValue` - The header value to parse

##### Returns:

[](#returns)

- ***\\Corpus\\HttpMessageUtils\\Authorization\\AuthorizationPartsInterface*** | ***null*** - AuthorizationParts on success, null on failure. Reasons for failure include empty string and non-RFC7235 compliant header values.

---

#### Method: AuthorizationHeaderParser-&gt;parseServerRequest

[](#method-authorizationheaderparser-parseserverrequest)

```
function parseServerRequest(\Psr\Http\Message\ServerRequestInterface $request [, string $headerName = self::DEFAULT_HEADER]) : ?\Corpus\HttpMessageUtils\Authorization\AuthorizationPartsInterface
```

Helper to easily parse from a PSR ServerRequestInterface

##### Parameters:

[](#parameters-2)

- ***\\Psr\\Http\\Message\\ServerRequestInterface*** `$request` - The PSR ServerRequestInterface to read from
- ***string*** `$headerName` - Optional header name to parse. Defaults to Authorization.

##### Returns:

[](#returns-1)

- ***\\Corpus\\HttpMessageUtils\\Authorization\\AuthorizationPartsInterface*** | ***null*** - AuthorizationParts on success, null on failure.

### Class: Corpus\\HttpMessageUtils\\Authorization\\AuthorizationPartsInterface

[](#class-corpushttpmessageutilsauthorizationauthorizationpartsinterface)

Representation of the parts of an Authorization Header: `Authorization:  `

#### Method: AuthorizationPartsInterface-&gt;getType

[](#method-authorizationpartsinterface-gettype)

```
function getType() : string
```

The specified authorization type

---

#### Method: AuthorizationPartsInterface-&gt;getCredentials

[](#method-authorizationpartsinterface-getcredentials)

```
function getCredentials() : string
```

The specified authorization credentials

### Class: Corpus\\HttpMessageUtils\\ProxyAwareSchemer

[](#class-corpushttpmessageutilsproxyawareschemer)

Utility to map a Uri or ServerRequestInterface's Uri to the external scheme detected from a proxy such as an AWS load balancer.

Will only ever upgrade to https, never downgrade.

### Example:

[](#example-1)

```
$serverRequest = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
$serverRequest = (new \Corpus\HttpMessageUtils\ProxyAwareSchemer)->withUriWithDetectedScheme($serverRequest);
```

```
