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

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

gandung/http-message
====================

PSR-7 HTTP Message Implementation in PHP

v1.0.0(8y ago)2331BSD-3-ClausePHP

Since Sep 20Pushed 8y ago2 watchersCompare

[ Source](https://github.com/plvhx/psr7-http-message)[ Packagist](https://packagist.org/packages/gandung/http-message)[ RSS](/packages/gandung-http-message/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (1)

PSR-7 HTTP Message
==================

[](#psr-7-http-message)

[![Build Status](https://camo.githubusercontent.com/b02b988dc8f5221613b128a0cc27e4ee2039a9a1d2a9e6912525804775f24ffe/68747470733a2f2f7472617669732d63692e6f72672f706c7668782f707372372d687474702d6d6573736167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/plvhx/psr7-http-message)

This is [PSR-7 HTTP message](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) implementation in PHP.

Response
========

[](#response)

Initiate a response
-------------------

[](#initiate-a-response)

### With string as body parameter

[](#with-string-as-body-parameter)

```
use Gandung\Psr7\Response;

$content = 'this is a text.';
$response = new Response($content, 200, ['Content-Type' => 'text/plain']);

echo sprintf("%s\n", $response);

```

### With object which implements `Psr\Http\Message\StreamInterface`

[](#with-object-which-implements-psrhttpmessagestreaminterface)

```
use Gandung\Psr7\PhpTempStream;
use Gandung\Psr7\Response;

$content = 'this is a text.';
$stream = new PhpTempStream;
$stream->write($content);
$response = new Response($stream, 200, ['Content-Type' => 'text/plain']);

echo sprintf("%s\n", $response);

```

### With local (fopen() like function) or remote (fsockopen() like function) stream resource

[](#with-local-fopen-like-function-or-remote-fsockopen-like-function-stream-resource)

```
use Gandung\Psr7\Response;

$handler = fopen('php://temp', 'r+b');
fseek($handler, 0);
fwrite($handler, 'this is a text.');
$response = new Response($handler, 200, ['Content-Type' => 'text/plain']);

echo sprintf("%s\n", $response);

```

Redirect Response
=================

[](#redirect-response)

Initiating HTTP redirect response
---------------------------------

[](#initiating-http-redirect-response)

### With URI string

[](#with-uri-string)

```
use Gandung\Psr7\Response\RedirectResponse;

$response = new RedirectResponse('http://example.com/a/b/c?api_version=1.0');

```

### With URI object

[](#with-uri-object)

```
use Gandung\Psr7\Uri;
use Gandung\Psr7\Response\RedirectResponse;

$uri = (new Uri())
	->withScheme('http')
	->withHost('example.com')
	->withPath('/a/b/c')
	->withQuery('api_version=1.0');
$response = new RedirectResponse($uri);

```

Empty Response
==============

[](#empty-response)

Initiating HTTP empty response
------------------------------

[](#initiating-http-empty-response)

```
use Gandung\Psr7\Response\EmptyResponse;

$response = new EmptyResponse;

```

Request
=======

[](#request)

Initiating a request
--------------------

[](#initiating-a-request)

### With URI string

[](#with-uri-string-1)

```
use Gandung\Psr7\Request;

$request = new Request('GET', 'http://example.com/a/b/c?api_version=1.0');

```

### With URI object

[](#with-uri-object-1)

```
use Gandung\Psr7\Request;
use Gandung\Psr7\Uri;

$uri = (new Uri())
	->withScheme('http')
	->withHost('example.com')
	->withPath('/a/b/c')
	->withQuery('api_version=1.0');
$request = new Request('GET', $uri);

```

Stream
======

[](#stream)

File stream
-----------

[](#file-stream)

```
use Gandung\Psr7\FileStream;

$stream = new FileStream('your-file', 'r');

```

`php://input` stream
--------------------

[](#phpinput-stream)

```
use Gandung\Psr7\PhpInputStream;

$stream = new PhpInputStream;

```

`php://temp` stream
-------------------

[](#phptemp-stream)

```
use Gandung\Psr7\PhpTempStream;

$stream = new PhpTempStream;
$stream->write('this is a text.');

echo sprintf("%s\n", (string)$stream);

```

Common Stream
-------------

[](#common-stream)

```
use Gandung\Psr7\Stream;

$handler = fopen('your-file', 'r');
fseek($handler, 0);
fwrite($handler, 'this is a text.');
$stream = new Stream($handler);

echo sprintf("%s\n", (string)$stream);

```

URI
===

[](#uri)

With whole constructed URI (RFC 3986)
-------------------------------------

[](#with-whole-constructed-uri-rfc-3986)

```
use Gandung\Psr7\Uri;

$uri = new Uri('http://user:password@example.com:13123/a/b/c?foo=bar#fragment');

echo sprintf("%s\n", $uri);

```

With separated URI components immutably
---------------------------------------

[](#with-separated-uri-components-immutably)

```
use Gandung\Psr7\Uri;

$uri = (new Uri())
	->withScheme('http')
	->withUserInfo('user', 'password')
	->withHost('example.com')
	->withPort(13123)
	->withPath('/a/b/c')
	->withQuery('foo=bar')
	->withFragment('fragment');

echo sprintf("%s\n", $uri);

```

File Upload
===========

[](#file-upload)

This works in SAPI and non-SAPI PHP environment
-----------------------------------------------

[](#this-works-in-sapi-and-non-sapi-php-environment)

```
use Gandung\Psr7\UploadedFile;

$uploadedFile = new UploadedFile(
	'source-file',
	'destination-file',
	\UPLOAD_ERR_OK
);

```

Server Request
==============

[](#server-request)

Only with URI
-------------

[](#only-with-uri)

```
use Gandung\Psr7\ServerRequest;

$uri = (new Uri())
	->withScheme('http')
	->withHost('example.com')
	->withPath('/a/b/c')
	->withQuery('foo=bar');
$request = new ServerRequest($uri);

```

From PHP superglobal variables
------------------------------

[](#from-php-superglobal-variables)

```
use Gandung\Psr7\ServerRequestFactory;

$request = ServerRequestFactory::createFromGlobals();

```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

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 ~130 days

Total

2

Last Release

3114d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3601403?v=4)[gandung](/maintainers/gandung)[@Gandung](https://github.com/Gandung)

---

Top Contributors

[![plvhx](https://avatars.githubusercontent.com/u/12740518?v=4)](https://github.com/plvhx "plvhx (28 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.4k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k52](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k20](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36826.2k2](/packages/telnyx-telnyx-php)[mimmi20/browser-detector

Library to detect Browsers and Devices

49158.4k5](/packages/mimmi20-browser-detector)

PHPackages © 2026

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