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

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

kigkonsult/http-message
=======================

Psr http-message server-side message, response and stream implementation

v1.1(4y ago)111LGPL-3.0-or-laterPHPPHP &gt;=7.0CI failing

Since Apr 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/iCalcreator/http-message)[ Packagist](https://packagist.org/packages/kigkonsult/http-message)[ Docs](https://kigkonsult.se)[ Fund](https://paypal.me/kigkonsult)[ RSS](/packages/kigkonsult-http-message/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

The Kigkonsult\\Http\\Message package provide [PSR](https://github.com/php-fig/http-message) server-side

> *Message* class

> *Stream* class

> *Response* class

###### Message class

[](#message-class)

- implements [Psr\\Http\\Message\\MessageInterface](https://github.com/php-fig/http-message)
- constructor args: body, headers, protocolVersion

###### Stream class

[](#stream-class)

- implements [Psr\\Http\\Message\\StreamInterface](https://github.com/php-fig/http-message)
- constructor args: content, streamWrapper/resource, mode
- with a (static) factory methods
    - `factoryFromString( content [, streamWrapper [, mode ]] )`
    - `factoryFromResource( resource )`

###### Response class

[](#response-class)

- extends Message
- implements
    - [Psr\\Http\\Message\\ResponseInterface](https://github.com/php-fig/http-message)
    - [Fig\\Http\\Message\\StatusCodeInterface](https://github.com/php-fig/http-message-util)
- constructor args: body, status, headers

The Response class has an added property:

- `rawBody`
    - response body (type mixed) before serialization/encoding

in parallel with

- `(Psr\Http\Message\)ServerRequest::parsedBody`
- `(Psr\Http\Message\)ServerRequest::body`

with corresponding methods:

- `getRawBody()`
    - Return rawBody
- `isRawBodyEmpty()`
    - Return bool true on empty rawBody
- `withRawBody()`
    - Return new instance with rawBody

and two rawBody/body methods

- `getResponseBody()`
    - Return rawBody if not empty else body
- `isBodyEmpty()`
    - Return bool true if (serialized/encoded) body is empty

Two statusCode methods are added:

- `assertStatusCode()`
    - (static) validates statusCode, throws InvalidArgumentException on error
- `isBodyLessResponse()`
    - Return bool true on statusCode 1xx, 204 or 304

###### Installation

[](#installation)

[Composer](https://getcomposer.org/), from the Command Line:

```
composer require kigkonsult/http-master:dev-master

```

Composer, in your `composer.json`:

```
{
    "require": {
        "kigkonsult/http-master": "dev-master"
    }
}
```

Composer, acquire access

```
