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

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

jitsu/http
==========

Object-oriented HTTP request and response interfaces

0.2.1(6y ago)2671MITPHPPHP &gt;=5.3.0

Since Sep 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bdusell/jitsu-http)[ Packagist](https://packagist.org/packages/jitsu/http)[ RSS](/packages/jitsu-http/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (1)

jitsu/http
----------

[](#jitsuhttp)

This package defines an abstract, object-oriented interface for interacting with HTTP requests and responses, and implements this interface for the request and response data which are traditionally accessible by the PHP script through superglobal variables, global functions, etc. This makes it possible to decouple application code from the specifics of where requests come from and where responses go, enabling dependency injection and unit testing.

Do also take a look at [PSR-7](http://www.php-fig.org/psr/psr-7/), which is designed to meet the same goals and, obviously, has more community traction.

This package is part of [Jitsu](https://github.com/bdusell/jitsu).

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

[](#installation)

Install this package with [Composer](https://getcomposer.org/):

```
composer require jitsu/http
```

Namespace
---------

[](#namespace)

All classes and interfaces are defined under the namespace `Jitsu`. The main ones are defined under `Jitsu\Http`.

API
---

[](#api)

### interface Jitsu\\Http\\RequestInterface

[](#interface-jitsuhttprequestinterface)

An abstract interface to an HTTP request.

#### $request\_interface-&gt;getMethod()

[](#request_interface-getmethod)

Get the HTTP method used in the request.

Typereturns`string`#### $request\_interface-&gt;getUri()

[](#request_interface-geturi)

Get the raw URI sent in the request.

Typereturns`string`#### $request\_interface-&gt;getProtocol()

[](#request_interface-getprotocol)

Get the protocol/version string used in the request.

Typereturns`string`#### $request\_interface-&gt;getScheme()

[](#request_interface-getscheme)

Get the scheme used in the request (`http` or `https`).

Typereturns`string`#### $request\_interface-&gt;getHeader($name)

[](#request_interface-getheadername)

Look up a header sent in the request.

Returns the value of the header with the given name (case-insensitive), or `null` if the header was not sent.

Type**`$name`**`string`returns`string#### $request\_interface-&gt;getAllHeaders()

[](#request_interface-getallheaders)

Get all of the headers sent in the request.

Returns an array mapping the original header names to their values.

Typereturns`string[]`#### $request\_interface-&gt;getBody()

[](#request_interface-getbody)

Get the request body as a single string.

Typereturns`string`#### $request\_interface-&gt;getBodyStream()

[](#request_interface-getbodystream)

Get a readable file stream handle to the request body.

Typereturns`resource`#### $request\_interface-&gt;getOriginIpAddress()

[](#request_interface-getoriginipaddress)

Get the IP address of the remote endpoint.

Typereturns`string`#### $request\_interface-&gt;getOriginPort()

[](#request_interface-getoriginport)

Get the port number of the remote endpoint.

Typereturns`string`### interface Jitsu\\Http\\ResponseInterface

[](#interface-jitsuhttpresponseinterface)

An abstract interface to an HTTP response.

#### $response\_interface-&gt;setStatus($version, $code, $reason)

[](#response_interface-setstatusversion-code-reason)

Set the HTTP status line of the response.

TypeDescription**`$version`**`string`An HTTP version string. The modern version string is `HTTP/1.1`.**`$code`**`intstring`**`$reason`**`string`A reason string describing the status code.#### $response\_interface-&gt;addHeader($name, $value)

[](#response_interface-addheadername-value)

Send an HTTP header in the response.

Does not override previously sent headers with the same name.

Type**`$name`**`string`**`$value`**`string`#### $response\_interface-&gt;flushOutputBuffer()

[](#response_interface-flushoutputbuffer)

Flush the PHP output buffer to the body of the response.

#### $response\_interface-&gt;sentHeaders()

[](#response_interface-sentheaders)

Determine whether the headers were sent.

If the headers were already sent, they may no longer be modified.

Typereturns`bool`### class Jitsu\\Http\\RequestBase

[](#class-jitsuhttprequestbase)

Implements `RequestInterface`.

An extension of `RequestInterface` which offers some utility methods.

#### $request\_base-&gt;fullUrl()

[](#request_base-fullurl)

Get the full request URL.

This includes the scheme, host name, path, and query string. This is in raw form and not URL-decoded.

Typereturns`string`#### $request\_base-&gt;scheme()

[](#request_base-scheme)

Get the request scheme.

Typereturns`string`#### $request\_base-&gt;protocol()

[](#request_base-protocol)

Get the protocol/version string used in the request.

Typereturns`string`#### $request\_base-&gt;host()

[](#request_base-host)

Get the value of the `Host` header.

Typereturns`string`#### $request\_base-&gt;method()

[](#request_base-method)

Get the HTTP method used in the request.

Always returned in upper case (e.g. `'GET'`, `'PUT'`, etc.).

Typereturns`string`#### $request\_base-&gt;uri()

[](#request_base-uri)

Get the raw URI sent in the request.

This consists of the path and query string of the request. Note that this is in raw form and not URL-decoded.

Typereturns`string`#### $request\_base-&gt;path()

[](#request_base-path)

Get the path part of the request URI.

Note that this is in raw form and not URL-decoded.

Typereturns`string`#### $request\_base-&gt;queryString()

[](#request_base-querystring)

Get the query string of the request URI.

Note that this is in raw form and not URL-decoded.

Typereturns`string`#### $request\_base-&gt;form($name, $default = null)

[](#request_base-formname-default--null)

Look up a form-encoded parameter from the request.

TypeDescription**`$name`**`string`**`$default`**`mixed`Default value to get if the parameter does not exist.returns`stringnull#### $request\_base-&gt;formParams()

[](#request_base-formparams)

Get all of the form-encoded parameters from the request.

Returns an array mapping the names of the form-encoded parameters sent in the request to their values. All keys and values are decoded. The parameters are taken from the appropriate part of the request based on the HTTP method used. For `GET`, `DELETE`, etc. they are parsed from the query string, and otherwise they are parsed from the request body.

Typereturns`string[]`#### $request\_base-&gt;header($name, $default = null)

[](#request_base-headername-default--null)

Look up a header sent in the request.

TypeDescription**`$name`**`string`Case-insensitive name of the header.**`$default`**`mixed`Default value to get if the header does not exist.returns`stringnull#### $request\_base-&gt;headers()

[](#request_base-headers)

Get all headers sent in the request.

Returns an array mapping the original header names to their values.

Typereturns`string[]`#### $request\_base-&gt;contentType()

[](#request_base-contenttype)

Get the content type of the request.

Typereturns`string#### $request\_base-&gt;acceptableContentTypes()

[](#request_base-acceptablecontenttypes)

Parse the `Accept` header into a list of acceptable content types.

Returns an associative array mapping content type strings to their respective quality ratings, ordered in descending order of quality.

Typereturns`string[]`#### $request\_base-&gt;accepts($content\_type)

[](#request_base-acceptscontent_type)

Return whether the request will accept a certain content type.

Type**`$content_type`**`string`returns`bool`#### $request\_base-&gt;negotiateContentType($acceptable)

[](#request_base-negotiatecontenttypeacceptable)

Determine the request's most acceptable content type.

Given an array of acceptable content types, returns the index of the content type with the highest quality rating in the `Accept`header. Returns `null` if no content type is acceptable.

Type**`$acceptable`**`string[]`returns`int#### $request\_base-&gt;referer()

[](#request_base-referer)

Alias of `referrer`.

Alias of the correctly spelled `referrer`. See `\Jitsu\RequestBase::referrer()`.

Typereturns`string#### $request\_base-&gt;referrer()

[](#request_base-referrer)

Get the HTTP referrer URI or `null` if it was not sent.

Typereturns`string#### $request\_base-&gt;cookie($name, $default = null)

[](#request_base-cookiename-default--null)

Look up a cookie sent in the request.

Parses and decodes the cookie value.

Type**`$name`**`string`returns`string#### $request\_base-&gt;cookies()

[](#request_base-cookies)

Get the cookies sent in the request.

Parses and decodes the cookie values.

TODO: This is currently not implemented.

Typereturns`string[]`#### $request\_base-&gt;body()

[](#request_base-body)

Return the request body as a single string.

Typereturns`string`#### $request\_base-&gt;bodyStream()

[](#request_base-bodystream)

Return a readable file stream handle to the request body.

Typereturns`resource`#### $request\_base-&gt;originIpAddress()

[](#request_base-originipaddress)

Get the IP address of the remote endpoint.

Typereturns`string`#### $request\_base-&gt;originPort()

[](#request_base-originport)

Get the port number of the remote endpoint.

Typereturns`string`### class Jitsu\\Http\\ResponseBase

[](#class-jitsuhttpresponsebase)

Implements `ResponseInterface`.

An extension of `ResponseInterface` which offers some utility methods.

#### $response\_base-&gt;setStatusCode($code, $reason = '')

[](#response_base-setstatuscodecode-reason--)

Set the status code of the response.

TypeDescription**`$code`**`intstring`**`$reason`**`string`An optional reason string. If not given, a default is used.#### abstract public function statusCode()

[](#abstract-public-function-statuscode)

Get the current status code set on this response.

#### $response\_base-&gt;setContentType($type)

[](#response_base-setcontenttypetype)

Set the content type of the response.

Type**`$type`**`string`#### $response\_base-&gt;addCookie($name, $value, $attrs)

[](#response_base-addcookiename-value-attrs)

Add a cookie to the response.

TODO: This has yet to be implemented.

TypeDescription**`$name`**`string`**`$value`**`string`**`$attrs`**`(stringbool)\[\]`#### $response\_base-&gt;redirect($url, $code, $reason = '')

[](#response_base-redirecturl-code-reason--)

Issue a redirect to another URL.

Note that this does NOT exit the current process. Keep in mind that relying on the client to respect this header and close the connection for you is potentially a huge security hole.

The response code is also set here. The response code should be a 3XX code.

#### $response\_base-&gt;startOutputBuffering()

[](#response_base-startoutputbuffering)

Start buffering PHP output.

#### $response\_base-&gt;clearOutputBuffer()

[](#response_base-clearoutputbuffer)

Discard the contents of the PHP output buffer.

### class Jitsu\\Http\\CurrentRequest

[](#class-jitsuhttpcurrentrequest)

Extends `RequestBase`.

A sub-class of `RequestBase` and implementation of `RequestInterface` for the current HTTP request.

#### $current\_request-&gt;getMethod()

[](#current_request-getmethod)

#### $current\_request-&gt;getUri()

[](#current_request-geturi)

#### $current\_request-&gt;getProtocol()

[](#current_request-getprotocol)

#### $current\_request-&gt;getScheme()

[](#current_request-getscheme)

#### $current\_request-&gt;getHeader($name)

[](#current_request-getheadername)

#### $current\_request-&gt;getAllHeaders()

[](#current_request-getallheaders)

#### $current\_request-&gt;getBody()

[](#current_request-getbody)

#### $current\_request-&gt;getBodyStream()

[](#current_request-getbodystream)

#### $current\_request-&gt;getOriginIpAddress()

[](#current_request-getoriginipaddress)

#### $current\_request-&gt;getOriginPort()

[](#current_request-getoriginport)

#### $current\_request-&gt;method()

[](#current_request-method)

#### $current\_request-&gt;path()

[](#current_request-path)

#### $current\_request-&gt;queryString()

[](#current_request-querystring)

#### $current\_request-&gt;form($name, $default = null)

[](#current_request-formname-default--null)

#### $current\_request-&gt;formParams()

[](#current_request-formparams)

#### $current\_request-&gt;cookie($name, $default = null)

[](#current_request-cookiename-default--null)

#### $current\_request-&gt;cookies()

[](#current_request-cookies)

#### $current\_request-&gt;originIpAddress()

[](#current_request-originipaddress)

#### $current\_request-&gt;originPort()

[](#current_request-originport)

#### $current\_request-&gt;timestamp()

[](#current_request-timestamp)

### class Jitsu\\Http\\CurrentResponse

[](#class-jitsuhttpcurrentresponse)

Extends `ResponseBase`.

A sub-class of `ResponseBase` and implementation of `ResponseInterface` for the current HTTP response.

#### $current\_response-&gt;setStatus($version, $code, $reason)

[](#current_response-setstatusversion-code-reason)

#### $current\_response-&gt;setStatusCode($code, $reason = null)

[](#current_response-setstatuscodecode-reason--null)

#### $current\_response-&gt;statusCode()

[](#current_response-statuscode)

#### $current\_response-&gt;addHeader($name, $value)

[](#current_response-addheadername-value)

#### $current\_response-&gt;addCookie($name, $value, $attrs = array()

[](#current_response-addcookiename-value-attrs--array)

#### $current\_response-&gt;deleteCookie($name, $attrs)

[](#current_response-deletecookiename-attrs)

#### $current\_response-&gt;redirect($url, $code, $reason = null)

[](#current_response-redirecturl-code-reason--null)

#### $current\_response-&gt;flushOutputBuffer()

[](#current_response-flushoutputbuffer)

#### $current\_response-&gt;sentHeaders()

[](#current_response-sentheaders)

### class Jitsu\\Request

[](#class-jitsurequest)

Get information about the current HTTP request being processed.

The class `\Jitsu\Http\CurrentRequest` provides the same information through an object-oriented interface. It is recommended to use that instead.

#### Request::scheme()

[](#requestscheme)

Get the URI's scheme (`http` or `https`).

Typereturns`string`#### Request::protocol()

[](#requestprotocol)

Get the protocol/version indicated in the HTTP request.

Typereturns`string`#### Request::host()

[](#requesthost)

Get the value of the `Host` header.

Typereturns`string`#### Request::method()

[](#requestmethod)

Get the HTTP method used in the request (`GET`, `POST`, etc.).

Typereturns`string`#### Request::uri()

[](#requesturi)

Get the full, raw request URI.

Typereturns`string`#### Request::queryString()

[](#requestquerystring)

Get the query string of the URI.

Typereturns`string`#### Request::form($name, $default = null)

[](#requestformname-default--null)

Look up a form-encoded parameter from the request.

TypeDescription**`$name`**`string`**`$default`**`mixed`A default value to get if the parameter does not exist.returns`stringnull#### Request::formParams()

[](#requestformparams)

Get all of the request's form-encoded parameters.

Typereturns`string[]`#### Request::header($name, $default = null)

[](#requestheadername-default--null)

Look up an HTTP header in the request.

TypeDescription**`$name`**`string`**`$default`**`mixed`Default value to get if the header does not exist.returns`stringnull#### Request::headers()

[](#requestheaders)

Get all HTTP headers sent with the request.

If PHP is running through Apache (the function `apache_request_header` is available), this should return the header names in their original case. Otherwise, they will be in lower case.

Typereturns`string[]`#### Request::cookie($name, $default = null)

[](#requestcookiename-default--null)

Look up cookies sent in the request.

TypeDescription**`$name`**`string`**`$default`**`mixed`Default value to get if the cookie does not exist.returns`stringnull#### Request::cookies()

[](#requestcookies)

Get all cookies sent in the request as an array.

Typereturns`string[]`#### Request::body()

[](#requestbody)

Slurp the raw input sent in the request body into a single string.

The result is cached, so this function may be called more than once.

Typereturns`string`#### Request::bodyStream()

[](#requestbodystream)

Return a file stream handle to the request body.

Typereturns`resource`#### Request::file($name)

[](#requestfilename)

Look up information about a file sent in a multipart-form request.

Type**`$name`**`string`returns`array`#### Request::files()

[](#requestfiles)

Get information about all files sent in a multipart-form request.

Typereturns`array[]`#### Request::saveFile($name, $dest\_path)

[](#requestsavefilename-dest_path)

Save a file uploaded as a multipart-form parameter.

Saves the file uploaded under the form parameter `$name` to the path `$dest_path` on the filesystem.

TypeDescription**`$name`**`string`**`$dest_path`**`string`throws`\RuntimeException`Thrown if the file is missing, if there is an error code associated with this file upload, or if it could not be saved.#### Request::originIpAddress()

[](#requestoriginipaddress)

Get the IP address of the remote endpoint.

Typereturns`string`#### Request::originPort()

[](#requestoriginport)

Get the port number of the remote endpoint.

Typereturns`string`#### Request::timestamp()

[](#requesttimestamp)

Timestamp of the start of the request.

Typereturns`int`### class Jitsu\\Response

[](#class-jitsuresponse)

Utilities for building the current HTTP response about to be sent.

The class `\Jitsu\Http\CurrentResponse` provides the same capabilities through an object-oriented interface. It is recommended to use that instead.

#### Response::setStatus($version, $code, $reason)

[](#responsesetstatusversion-code-reason)

Set the response status line.

Note that this is mutually exclusive with `code`.

Type**`$version`**`string`**`$code`**`int**`$reason`**`string`#### Response::setStatusCode($code)

[](#responsesetstatuscodecode)

Set the response code.

Automatically sets an appropriate reason string.

Note that this is mutually exclusive with `status`.

Type**`$code`**`int#### Response::statusCode()

[](#responsestatuscode)

Get the currently set response code.

Typereturns`int`#### Response::addHeader($name, $value)

[](#responseaddheadername-value)

Set a header in the response.

Must be called before output is written, just like PHP `header`.

Does not override previously sent header with the same name.

Type**`$name`**`string`**`$value`**`string`#### Response::addCookie($name, $value, $expires = null, $path = null, $domain = null)

[](#responseaddcookiename-value-expires--null-path--null-domain--null)

Set a cookie in the response.

Type**`$name`**`string`**`$value`**`string`**`$expires`**`int**`$path`**`string**`$domain`**`string#### Response::deleteCookie($name, $domain = null, $path = null)

[](#responsedeletecookiename-domain--null-path--null)

Indicate in the response to delete a cookie.

Type**`$name`**`string`**`$domain`**`string**`$path`**`string#### Response::redirect($url, $code)

[](#responseredirecturl-code)

Issue an HTTP redirect.

Type**`$url`**`string`**`$code`**`int#### Response::startOutputBuffering()

[](#responsestartoutputbuffering)

Start buffering PHP output.

#### Response::flushOutputBuffer()

[](#responseflushoutputbuffer)

Flush the PHP output buffer and stop buffering.

#### Response::clearOutputBuffer()

[](#responseclearoutputbuffer)

Discard the contents of the PHP output buffer and stop buffering.

#### Response::sentHeaders()

[](#responsesentheaders)

Determine whether the headers were sent.

If the headers were already sent, they may no longer be modified.

Typereturns`bool`#### Response::bodyStream()

[](#responsebodystream)

Get a handle to a writable file stream to the response body.

Typereturns`resource`

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

2289d ago

### Community

Maintainers

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

---

Top Contributors

[![bdusell](https://avatars.githubusercontent.com/u/5336190?v=4)](https://github.com/bdusell "bdusell (10 commits)")

---

Tags

abstractionhttphttp-requesthttp-responseinterfacephpweb-developmenthttpresponserequest

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[fig/http-message-util

Utility classes and constants for use with PSR-7 (psr/http-message)

39489.0M274](/packages/fig-http-message-util)[nette/http

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

48819.2M541](/packages/nette-http)[psr/http-server-handler

Common interface for HTTP server-side request handler

177101.3M921](/packages/psr-http-server-handler)

PHPackages © 2026

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