PHPackages                             proteins/response - 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. proteins/response

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

proteins/response
=================

Handles the HTTP Response for the current execution

1.0.5(6y ago)0441MITPHPPHP ^7.2

Since May 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/php-protein/response)[ Packagist](https://packagist.org/packages/proteins/response)[ RSS](/packages/proteins-response/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (1)

[![](https://raw.githubusercontent.com/php-protein/docs/master/assets/protein-large.png)](https://raw.githubusercontent.com/php-protein/docs/master/assets/protein-large.png)

Protein | Response
==================

[](#protein--response)

The response module wrap and handles the payload sended to the request agent.
-----------------------------------------------------------------------------

[](#the-response-module-wrap-and-handles-the-payload-sended-to-the-request-agent)

### Install

[](#install)

---

```
composer require proteins/response

```

Require the class via :

```
use Proteins\Response;
```

### Appending data to the response

[](#appending-data-to-the-response)

---

Append a string to the response buffer via the `add` method.

```
Response::add('Hello world!');
```

### Changing the content type

[](#changing-the-content-type)

---

The `type` method accepts a MIME type string (or a `Response::TYPE_*` constant) for the body content type.

```
Response::send();
```

### Adding an header to the response

[](#adding-an-header-to-the-response)

---

The `header($name, $value)` method set an header for being sended to the request agent.

```
Response::header('Authorization','Bearer mF_9.B5f-4.1JqM');
```

```
Authorization: Bearer mF_9.B5f-4.1JqM

```

### Get all defined headers

[](#get-all-defined-headers)

---

```
$response_headers = Response::headers();
```

### Get response body

[](#get-response-body)

---

```
$response_body = Response::body();
```

### Set the entire response body

[](#set-the-entire-response-body)

---

You can set the entire response body by passing a parameter to the `body` method.

```
Response::body($new_body);
```

### Set the HTTP response status

[](#set-the-http-response-status)

---

You can set the HTTP response status with the `status` method.

```
Response::status(401);
```

The `error($code, $message='')` method is used to pass errors.

> This method triggers the `core.response.error` event.

```
Response::error(401, "User not authorized");
```

### Force download of response body

[](#force-download-of-response-body)

---

You can force download of response body with `download` method passing filename as parameter. Pass a falsy value to disable download.

```
Response::download("export.csv");
```

Download method support also array as parameter with raw string data.

```
Response::download([
	"filename" 	=> "export.csv",
	"charset" 	=> "utf-8",
	"mime" 		=> "text/csv",
	"body" 		=> CSV::fromSQL("SELECT * FROM users")
]);
```

### HTTP/2 Server Push

[](#http2-server-push)

---

The HTTP/Server Push support is enabled via the `push` method.
If you have a list of resource links to be pushed in the next `Response::send` you can pass the URI and the resource type as defined in the [W3C Preload Draft](https://www.w3.org/TR/preload/#server-push-http-2)

```
Response::push('/assets/css/main.css');
Response::push('/assets/js/main.js');
```

If you don't pass resource type as a second parameter the code will be guess from the extension, however is better (faster) to specify the resource type (for the `as` parameter of the preload header format).

The current auto-discovered resource types are :

ExtensionsType`js``script``css``style``woff`,`woff2`,`ttf`,`eof``font``png`,`svg`,`gif`,`jpg``image`*other*`text````
Response::push('/assets/css/main.css','style');
Response::push('/assets/js/main.js','script');
```

Multiple resources can be passed to a single `push` call via an array :

```
Response::push([
  '/assets/css/main.css',
  '/assets/js/main.js',
]);
```

and as the same as the direct call version you can define resource types via array-keys :

```
Response::push([
  'style'  => '/assets/css/main.css',
  'script' => [
    '/assets/js/vendors.js',
    '/assets/js/main.js',
  ],
]);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Total

5

Last Release

2542d ago

### Community

Maintainers

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

---

Top Contributors

[![lastguest](https://avatars.githubusercontent.com/u/178900?v=4)](https://github.com/lastguest "lastguest (5 commits)")

### Embed Badge

![Health badge](/badges/proteins-response/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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