PHPackages                             jason-gao/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. jason-gao/http

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

jason-gao/http
==============

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

v2.4.8(8y ago)0405BSD-3-ClausePHPPHP &gt;=5.6.0

Since Jun 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/jason-gao/http)[ Packagist](https://packagist.org/packages/jason-gao/http)[ Docs](https://nette.org)[ RSS](/packages/jason-gao-http/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (4)Versions (36)Used By (0)

Nette HTTP Component
====================

[](#nette-http-component)

[![Downloads this Month](https://camo.githubusercontent.com/2484161fc4f3582a0dcbff335b0e9e9ede1e2d63bff600d693ee2a5cfbda9aae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e657474652f687474702e737667)](https://packagist.org/packages/nette/http)[![Build Status](https://camo.githubusercontent.com/9afd51fa31a5d6362e13f63bdbb77be22b150f99232344907882975a0a354115/68747470733a2f2f7472617669732d63692e6f72672f6e657474652f687474702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nette/http)[![Build Status Windows](https://camo.githubusercontent.com/977822ae07728fd952c9ebecd7187b14d05b98ee1683dfad95c3aedaef45b0ca/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f6769746875622f6e657474652f687474703f6272616e63683d6d6173746572267376673d74727565)](https://ci.appveyor.com/project/dg/http/branch/master)[![Coverage Status](https://camo.githubusercontent.com/4564fab65508ddb126b7c661586be59af54e3d4999da0b9d62769f3914384419/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e657474652f687474702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/nette/http?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/17c71dae21f487fc66cd21b96ce7bbd59abb644b1667d36ebd4c766f51360ea6/68747470733a2f2f706f7365722e707567782e6f72672f6e657474652f687474702f762f737461626c65)](https://github.com/nette/http/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/nette/http/blob/master/license.md)

Introduction
------------

[](#introduction)

HTTP request and response are encapsulated in `Nette\Http\Request` and `Nette\Http\Response` objects which offer comfortable API and also act as sanitization filter.

Documentation can be found on the [website](https://doc.nette.org/http-request-response).

Installation
------------

[](#installation)

The recommended way to install is via Composer:

```
composer require nette/http

```

It requires PHP version 5.6 and supports PHP up to 7.2. The dev-master version requires PHP 7.1.

HTTP Request
------------

[](#http-request)

Nette cleans out data sent by user from control and invalid characters.

The URL of the request is available as \[api:Nette\\Http\\UrlScript\] instance:

```
$url = $httpRequest->getUrl();
echo $url;       // e.g. https://nette.org/en/documentation?action=edit
echo $url->host; // nette.org
```

Determine current HTTP method:

```
echo $httpRequest->getMethod(); // GET, POST, HEAD, PUT

if ($httpRequest->isMethod('GET')) ...
```

Is the connection encrypted (HTTPS)?

```
echo $httpRequest->isSecured() ? 'yes' : 'no';
```

Is this an AJAX request?

```
echo $httpRequest->isAjax() ? 'yes' : 'no';
```

What is the user's IP address?

```
echo $httpRequest->getRemoteAddress(); // user's IP address
echo $httpRequest->getRemoteHost();    // and its DNS translation
```

What URL the user came from? Returned as \[Nette\\Http\\Url |urls\] object.

```
echo $httpRequest->getReferer()->host;
```

Request parameters:

```
$get = $httpRequest->getQuery();    // array of all URL parameters
$id = $httpRequest->getQuery('id'); // returns GET parameter 'id' (or null)

$post = $httpRequest->getPost();    // array of all POST parameters
$id = $httpRequest->getPost('id');  // returns POST parameter 'id' (or null)

$cookies = $httpRequest->getCookies(); // array of all cookies
$sessId = $httpRequest->getCookie('sess_id'); // returns the cookie (or null)
```

Uploaded files are encapsulated into \[api:Nette\\Http\\FileUpload\] objects:

```
$files = $httpRequest->getFiles(); // array of all uploaded files

$file = $httpRequest->getFile('avatar'); // returns one file
echo $file->getName(); // name of the file sent by user
echo $file->getSanitizedName(); // the name without dangerous characters
```

HTTP headers are also accessible:

```
// returns associative array of HTTP headers
$headers = $httpRequest->getHeaders();

// returns concrete header (case-insensitive)
$userAgent = $httpRequest->getHeader('User-Agent');
```

A useful method is `detectLanguage()`. You can pass it an array with languages supported by application and it returns the one preferred by browser. It is not magic, the method just uses the `Accept-Language` header.

```
// Header sent by browser: Accept-Language: cs,en-us;q=0.8,en;q=0.5,sl;q=0.3

$langs = array('hu', 'pl', 'en'); // languages supported in application

echo $httpRequest->detectLanguage($langs); // en
```

RequestFactory and URL filtering
--------------------------------

[](#requestfactory-and-url-filtering)

Object holding current HTTP request is created by \[api:Nette\\Http\\RequestFactory\]. Its behavior can be modified. It's possible to clean up URLs from characters that can get into them because of poorly implemented comment systems on various other websites by using filters:

```
$requestFactory = new Nette\Http\RequestFactory;

// remove spaces from path
$requestFactory->addUrlFilter('%20', '', PHP_URL_PATH);

// remove dot, comma or right parenthesis form the end of the URL
$requestFactory->addUrlFilter('[.,)]$');

// clean the path from duplicated slashes (default filter)
$requestFactory->addUrlFilter('/{2,}', '/', PHP_URL_PATH);
```

And then we let the factory generate a new `httpRequest` and we store it in a system container:

```
// $container is a system container
$container->addService('httpRequest', $requestFactory->createHttpRequest());
```

HTTP response
-------------

[](#http-response)

Whether it is still possible to send headers or change the status code tells the `isSent()` method. If it returns true, it won't be possible to send another header or change the status code.

In that case, any attempt to send header or change code invokes `Nette\InvalidStateException`. .\[caution\]

\[Response status code | \] can be sent and retrieved this way:

```
$httpResponse->setCode(Nette\Http\Response::S404_NOT_FOUND);

echo $httpResponse->getCode(); // 404
```

For better source code readability it is recommended to use predefined constants instead of actual numbers:

```
Http\IResponse::S200_OK
Http\IResponse::S204_NO_CONTENT
Http\IResponse::S300_MULTIPLE_CHOICES
Http\IResponse::S301_MOVED_PERMANENTLY
Http\IResponse::S302_FOUND
Http\IResponse::S303_SEE_OTHER
Http\IResponse::S303_POST_GET
Http\IResponse::S304_NOT_MODIFIED
Http\IResponse::S307_TEMPORARY_REDIRECT
Http\IResponse::S400_BAD_REQUEST
Http\IResponse::S401_UNAUTHORIZED
Http\IResponse::S403_FORBIDDEN
Http\IResponse::S404_NOT_FOUND
Http\IResponse::S410_GONE
Http\IResponse::S500_INTERNAL_SERVER_ERROR
Http\IResponse::S501_NOT_IMPLEMENTED
Http\IResponse::S503_SERVICE_UNAVAILABLE

```

Method `setContentType($type, $charset=null)` changes `Content-Type` response header:

```
$httpResponse->setContentType('text/plain', 'UTF-8');
```

Redirection to another URL is done by `redirect($url, $code=302)` method. Do not forget to terminate the script afterwards!

```
$httpResponse->redirect('http://example.com');
exit;
```

To set the document expiration date, we can use `setExpiration()` method. The parameter is either text data, number of seconds or a timestamp:

```
// browser cache expires in one hour
$httpResponse->setExpiration('+ 1 hours');
```

Now we send the HTTP response header:

```
$httpResponse->setHeader('Pragma', 'no-cache');

// or if we want to send the same header more times with different values
$httpResponse->addHeader('Pragma', 'no-cache');
```

Sent headers are also available:

```
// returns associative array of headers
$headers = $httpResponse->getHeaders();

// returns concrete header (case-insensitive)
$pragma = $httpResponse->getHeader('Pragma');
```

There are two methods for cookie manipulation: `setCookie()` and `deleteCookie()`.

```
// setCookie($name, $value, $time, [$path, [$domain, [$secure, [$httpOnly]]]])
$httpResponse->setCookie('lang', 'en', '100 days'); // send cookie

// deleteCookie($name, [$path, [$domain, [$secure]]])
$httpResponse->deleteCookie('lang'); // delete cookie
```

These two methods can take more parameters: `$path` (subdirectory where the cookie will be available), `$domain` and `$secure`. Their detailed description can be found in PHP manual for \[php:setcookie\] function.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 82.5% 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 ~39 days

Recently: every ~83 days

Total

35

Last Release

3015d ago

Major Versions

v2.4.4 → v3.0.0-alpha12017-02-02

PHP version history (3 changes)v2.2.0PHP &gt;=5.3.1

v2.4.0PHP &gt;=5.6.0

v3.0.0-alpha1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfe2039308a3330d27c5042b04fb30b92751dd44f57a766524d0e6819dd77cf7?d=identicon)[jason-gao](/maintainers/jason-gao)

---

Top Contributors

[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (477 commits)")[![JanTvrdik](https://avatars.githubusercontent.com/u/175109?v=4)](https://github.com/JanTvrdik "JanTvrdik (32 commits)")[![vrana](https://avatars.githubusercontent.com/u/117453?v=4)](https://github.com/vrana "vrana (13 commits)")[![Majkl578](https://avatars.githubusercontent.com/u/144181?v=4)](https://github.com/Majkl578 "Majkl578 (6 commits)")[![enumag](https://avatars.githubusercontent.com/u/539462?v=4)](https://github.com/enumag "enumag (5 commits)")[![fprochazka](https://avatars.githubusercontent.com/u/158625?v=4)](https://github.com/fprochazka "fprochazka (5 commits)")[![milo](https://avatars.githubusercontent.com/u/439140?v=4)](https://github.com/milo "milo (5 commits)")[![Vrtak-CZ](https://avatars.githubusercontent.com/u/112567?v=4)](https://github.com/Vrtak-CZ "Vrtak-CZ (4 commits)")[![hrach](https://avatars.githubusercontent.com/u/284263?v=4)](https://github.com/hrach "hrach (3 commits)")[![lexaurin](https://avatars.githubusercontent.com/u/428302?v=4)](https://github.com/lexaurin "lexaurin (3 commits)")[![stekycz](https://avatars.githubusercontent.com/u/865447?v=4)](https://github.com/stekycz "stekycz (2 commits)")[![hranicka](https://avatars.githubusercontent.com/u/3034538?v=4)](https://github.com/hranicka "hranicka (2 commits)")[![fabik](https://avatars.githubusercontent.com/u/816866?v=4)](https://github.com/fabik "fabik (2 commits)")[![patrickkusebauch](https://avatars.githubusercontent.com/u/1620948?v=4)](https://github.com/patrickkusebauch "patrickkusebauch (2 commits)")[![kravco](https://avatars.githubusercontent.com/u/115938?v=4)](https://github.com/kravco "kravco (2 commits)")[![integer](https://avatars.githubusercontent.com/u/160891?v=4)](https://github.com/integer "integer (1 commits)")[![pavelbier](https://avatars.githubusercontent.com/u/426724?v=4)](https://github.com/pavelbier "pavelbier (1 commits)")[![pavelkovar](https://avatars.githubusercontent.com/u/19745438?v=4)](https://github.com/pavelkovar "pavelkovar (1 commits)")[![radeksimko](https://avatars.githubusercontent.com/u/287584?v=4)](https://github.com/radeksimko "radeksimko (1 commits)")[![sallyx](https://avatars.githubusercontent.com/u/4263901?v=4)](https://github.com/sallyx "sallyx (1 commits)")

---

Tags

httpresponserequesturlproxynettesecuritysessioncookies

### Embed Badge

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

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

###  Alternatives

[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

48619.2M541](/packages/nette-http)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[aplus/http

Aplus Framework HTTP Library

2311.6M10](/packages/aplus-http)[contributte/psr7-http-message

PSR-7 (HTTP Message Interface) to Nette Framework

222.9M8](/packages/contributte-psr7-http-message)[pdeans/http

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

1466.2k3](/packages/pdeans-http)[workerman/psr7

PSR-7 message implementation that also provides common utility methods

1079.8k10](/packages/workerman-psr7)

PHPackages © 2026

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