{"id":27185944,"url":"https://github.com/bdusell/jitsu-http","last_synced_at":"2025-04-09T17:55:34.323Z","repository":{"id":56999474,"uuid":"42761577","full_name":"bdusell/jitsu-http","owner":"bdusell","description":"Object-oriented interfaces to HTTP requests and responses in PHP","archived":false,"fork":false,"pushed_at":"2020-02-11T08:21:07.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-20T00:41:19.922Z","etag":null,"topics":["abstraction","http","http-request","http-response","interface","php","web-development"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bdusell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-19T05:48:21.000Z","updated_at":"2024-05-08T11:37:39.000Z","dependencies_parsed_at":"2022-08-21T13:51:01.570Z","dependency_job_id":null,"html_url":"https://github.com/bdusell/jitsu-http","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bdusell","download_url":"https://codeload.github.com/bdusell/jitsu-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083590,"owners_count":21045122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstraction","http","http-request","http-response","interface","php","web-development"],"created_at":"2025-04-09T17:55:30.722Z","updated_at":"2025-04-09T17:55:34.290Z","avatar_url":"https://github.com/bdusell.png","language":"PHP","readme":"jitsu/http\n----------\n\nThis package defines an abstract, object-oriented interface for interacting\nwith HTTP requests and responses, and implements this interface for the request\nand response data which are traditionally accessible by the PHP script through\nsuperglobal variables, global functions, etc. This makes it possible to\ndecouple application code from the specifics of where requests come from and\nwhere responses go, enabling dependency injection and unit testing.\n\nDo also take a look at [PSR-7](http://www.php-fig.org/psr/psr-7/), which is\ndesigned to meet the same goals and, obviously, has more community traction.\n\nThis package is part of [Jitsu](https://github.com/bdusell/jitsu).\n\n## Installation\n\nInstall this package with [Composer](https://getcomposer.org/):\n\n```sh\ncomposer require jitsu/http\n```\n\n## Namespace\n\nAll classes and interfaces are defined under the namespace `Jitsu`. The\nmain ones are defined under `Jitsu\\Http`.\n\n## API\n\n### interface Jitsu\\\\Http\\\\RequestInterface\n\nAn abstract interface to an HTTP request.\n\n#### $request\\_interface-\u003egetMethod()\n\nGet the HTTP method used in the request.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_interface-\u003egetUri()\n\nGet the raw URI sent in the request.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_interface-\u003egetProtocol()\n\nGet the protocol/version string used in the request.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_interface-\u003egetScheme()\n\nGet the scheme used in the request (`http` or `https`).\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_interface-\u003egetHeader($name)\n\nLook up a header sent in the request.\n\nReturns the value of the header with the given name\n(case-insensitive), or `null` if the header was not sent.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| returns | `string|null` |\n\n#### $request\\_interface-\u003egetAllHeaders()\n\nGet all of the headers sent in the request.\n\nReturns an array mapping the original header names to their values.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### $request\\_interface-\u003egetBody()\n\nGet the request body as a single string.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_interface-\u003egetBodyStream()\n\nGet a readable file stream handle to the request body.\n\n|   | Type |\n|---|------|\n| returns | `resource` |\n\n#### $request\\_interface-\u003egetOriginIpAddress()\n\nGet the IP address of the remote endpoint.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_interface-\u003egetOriginPort()\n\nGet the port number of the remote endpoint.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n### interface Jitsu\\\\Http\\\\ResponseInterface\n\nAn abstract interface to an HTTP response.\n\n#### $response\\_interface-\u003esetStatus($version, $code, $reason)\n\nSet the HTTP status line of the response.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$version`** | `string` | An HTTP version string. The modern version string is `HTTP/1.1`. |\n| **`$code`** | `int|string` | An HTTP status code. |\n| **`$reason`** | `string` | A reason string describing the status code. |\n\n#### $response\\_interface-\u003eaddHeader($name, $value)\n\nSend an HTTP header in the response.\n\nDoes not override previously sent headers with the same name.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| **`$value`** | `string` |\n\n#### $response\\_interface-\u003eflushOutputBuffer()\n\nFlush the PHP output buffer to the body of the response.\n\n#### $response\\_interface-\u003esentHeaders()\n\nDetermine whether the headers were sent.\n\nIf the headers were already sent, they may no longer be modified.\n\n|   | Type |\n|---|------|\n| returns | `bool` |\n\n### class Jitsu\\\\Http\\\\RequestBase\n\nImplements `RequestInterface`.\n\nAn extension of `RequestInterface` which offers some utility methods.\n\n#### $request\\_base-\u003efullUrl()\n\nGet the full request URL.\n\nThis includes the scheme, host name, path, and query string. This is\nin raw form and not URL-decoded.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003escheme()\n\nGet the request scheme.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003eprotocol()\n\nGet the protocol/version string used in the request.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003ehost()\n\nGet the value of the `Host` header.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003emethod()\n\nGet the HTTP method used in the request.\n\nAlways returned in upper case (e.g. `'GET'`, `'PUT'`, etc.).\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003euri()\n\nGet the raw URI sent in the request.\n\nThis consists of the path and query string of the request. Note that\nthis is in raw form and not URL-decoded.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003epath()\n\nGet the path part of the request URI.\n\nNote that this is in raw form and not URL-decoded.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003equeryString()\n\nGet the query string of the request URI.\n\nNote that this is in raw form and not URL-decoded.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003eform($name, $default = null)\n\nLook up a form-encoded parameter from the request.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` |  |\n| **`$default`** | `mixed` | Default value to get if the parameter does not exist. |\n| returns | `string|null|mixed` |  |\n\n#### $request\\_base-\u003eformParams()\n\nGet all of the form-encoded parameters from the request.\n\nReturns an array mapping the names of the form-encoded parameters\nsent in the request to their values. All keys and values are\ndecoded. The parameters are taken from the appropriate part of the\nrequest based on the HTTP method used. For `GET`, `DELETE`, etc.\nthey are parsed from the query string, and otherwise they are\nparsed from the request body.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### $request\\_base-\u003eheader($name, $default = null)\n\nLook up a header sent in the request.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` | Case-insensitive name of the header. |\n| **`$default`** | `mixed` | Default value to get if the header does not exist. |\n| returns | `string|null|mixed` |  |\n\n#### $request\\_base-\u003eheaders()\n\nGet all headers sent in the request.\n\nReturns an array mapping the original header names to their values.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### $request\\_base-\u003econtentType()\n\nGet the content type of the request.\n\n|   | Type |\n|---|------|\n| returns | `string|null` |\n\n#### $request\\_base-\u003eacceptableContentTypes()\n\nParse the `Accept` header into a list of acceptable content types.\n\nReturns an associative array mapping content type strings to their\nrespective quality ratings, ordered in descending order of quality.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### $request\\_base-\u003eaccepts($content\\_type)\n\nReturn whether the request will accept a certain content type.\n\n|   | Type |\n|---|------|\n| **`$content_type`** | `string` |\n| returns | `bool` |\n\n#### $request\\_base-\u003enegotiateContentType($acceptable)\n\nDetermine the request's most acceptable content type.\n\nGiven an array of acceptable content types, returns the index of the\ncontent type with the highest quality rating in the `Accept`\nheader. Returns `null` if no content type is acceptable.\n\n|   | Type |\n|---|------|\n| **`$acceptable`** | `string[]` |\n| returns | `int|null` |\n\n#### $request\\_base-\u003ereferer()\n\nAlias of `referrer`.\n\nAlias of the correctly spelled `referrer`. See `\\Jitsu\\RequestBase::referrer()`.\n\n|   | Type |\n|---|------|\n| returns | `string|null` |\n\n#### $request\\_base-\u003ereferrer()\n\nGet the HTTP referrer URI or `null` if it was not sent.\n\n|   | Type |\n|---|------|\n| returns | `string|null` |\n\n#### $request\\_base-\u003ecookie($name, $default = null)\n\nLook up a cookie sent in the request.\n\nParses and decodes the cookie value.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| returns | `string|null` |\n\n#### $request\\_base-\u003ecookies()\n\nGet the cookies sent in the request.\n\nParses and decodes the cookie values.\n\nTODO: This is currently not implemented.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### $request\\_base-\u003ebody()\n\nReturn the request body as a single string.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003ebodyStream()\n\nReturn a readable file stream handle to the request body.\n\n|   | Type |\n|---|------|\n| returns | `resource` |\n\n#### $request\\_base-\u003eoriginIpAddress()\n\nGet the IP address of the remote endpoint.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### $request\\_base-\u003eoriginPort()\n\nGet the port number of the remote endpoint.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n### class Jitsu\\\\Http\\\\ResponseBase\n\nImplements `ResponseInterface`.\n\nAn extension of `ResponseInterface` which offers some utility methods.\n\n#### $response\\_base-\u003esetStatusCode($code, $reason = '')\n\nSet the status code of the response.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$code`** | `int|string` | HTTP status code. |\n| **`$reason`** | `string` | An optional reason string. If not given, a default is used. |\n\n#### abstract public function statusCode()\n\nGet the current status code set on this response.\n\n#### $response\\_base-\u003esetContentType($type)\n\nSet the content type of the response.\n\n|   | Type |\n|---|------|\n| **`$type`** | `string` |\n\n#### $response\\_base-\u003eaddCookie($name, $value, $attrs)\n\nAdd a cookie to the response.\n\nTODO: This has yet to be implemented.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` |  |\n| **`$value`** | `string` |  |\n| **`$attrs`** | `(string|bool)[]` | An array of attributes to assign to the cookie. If an attribute value is a boolean, the value determines whether to include the attribute name in the cookie (e.g. for `Secure` or `HttpOnly`). |\n\n#### $response\\_base-\u003eredirect($url, $code, $reason = '')\n\nIssue a redirect to another URL.\n\nNote that this does NOT exit the current process. Keep in mind that\nrelying on the client to respect this header and close the\nconnection for you is potentially a huge security hole.\n\nThe response code is also set here. The response code should be a\n3XX code.\n\n#### $response\\_base-\u003estartOutputBuffering()\n\nStart buffering PHP output.\n\n#### $response\\_base-\u003eclearOutputBuffer()\n\nDiscard the contents of the PHP output buffer.\n\n### class Jitsu\\\\Http\\\\CurrentRequest\n\nExtends `RequestBase`.\n\nA sub-class of `RequestBase` and implementation of `RequestInterface` for\nthe current HTTP request.\n\n#### $current\\_request-\u003egetMethod()\n\n#### $current\\_request-\u003egetUri()\n\n#### $current\\_request-\u003egetProtocol()\n\n#### $current\\_request-\u003egetScheme()\n\n#### $current\\_request-\u003egetHeader($name)\n\n#### $current\\_request-\u003egetAllHeaders()\n\n#### $current\\_request-\u003egetBody()\n\n#### $current\\_request-\u003egetBodyStream()\n\n#### $current\\_request-\u003egetOriginIpAddress()\n\n#### $current\\_request-\u003egetOriginPort()\n\n#### $current\\_request-\u003emethod()\n\n#### $current\\_request-\u003epath()\n\n#### $current\\_request-\u003equeryString()\n\n#### $current\\_request-\u003eform($name, $default = null)\n\n#### $current\\_request-\u003eformParams()\n\n#### $current\\_request-\u003ecookie($name, $default = null)\n\n#### $current\\_request-\u003ecookies()\n\n#### $current\\_request-\u003eoriginIpAddress()\n\n#### $current\\_request-\u003eoriginPort()\n\n#### $current\\_request-\u003etimestamp()\n\n### class Jitsu\\\\Http\\\\CurrentResponse\n\nExtends `ResponseBase`.\n\nA sub-class of `ResponseBase` and implementation of `ResponseInterface` for\nthe current HTTP response.\n\n#### $current\\_response-\u003esetStatus($version, $code, $reason)\n\n#### $current\\_response-\u003esetStatusCode($code, $reason = null)\n\n#### $current\\_response-\u003estatusCode()\n\n#### $current\\_response-\u003eaddHeader($name, $value)\n\n#### $current\\_response-\u003eaddCookie($name, $value, $attrs = array()\n\n#### $current\\_response-\u003edeleteCookie($name, $attrs)\n\n#### $current\\_response-\u003eredirect($url, $code, $reason = null)\n\n#### $current\\_response-\u003eflushOutputBuffer()\n\n#### $current\\_response-\u003esentHeaders()\n\n### class Jitsu\\\\Request\n\nGet information about the current HTTP request being processed.\n\nThe class `\\Jitsu\\Http\\CurrentRequest` provides the same information through\nan object-oriented interface. It is recommended to use that instead.\n\n#### Request::scheme()\n\nGet the URI's scheme (`http` or `https`).\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::protocol()\n\nGet the protocol/version indicated in the HTTP request.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::host()\n\nGet the value of the `Host` header.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::method()\n\nGet the HTTP method used in the request (`GET`, `POST`, etc.).\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::uri()\n\nGet the full, raw request URI.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::queryString()\n\nGet the query string of the URI.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::form($name, $default = null)\n\nLook up a form-encoded parameter from the request.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` |  |\n| **`$default`** | `mixed` | A default value to get if the parameter does not exist. |\n| returns | `string|null|mixed` |  |\n\n#### Request::formParams()\n\nGet all of the request's form-encoded parameters.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### Request::header($name, $default = null)\n\nLook up an HTTP header in the request.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` |  |\n| **`$default`** | `mixed` | Default value to get if the header does not exist. |\n| returns | `string|null|mixed` |  |\n\n#### Request::headers()\n\nGet all HTTP headers sent with the request.\n\nIf PHP is running through Apache (the function\n`apache_request_header` is available), this should return the\nheader names in their original case. Otherwise, they will be in\nlower case.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### Request::cookie($name, $default = null)\n\nLook up cookies sent in the request.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` |  |\n| **`$default`** | `mixed` | Default value to get if the cookie does not exist. |\n| returns | `string|null|mixed` |  |\n\n#### Request::cookies()\n\nGet all cookies sent in the request as an array.\n\n|   | Type |\n|---|------|\n| returns | `string[]` |\n\n#### Request::body()\n\nSlurp the raw input sent in the request body into a single string.\n\nThe result is cached, so this function may be called more than once.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::bodyStream()\n\nReturn a file stream handle to the request body.\n\n|   | Type |\n|---|------|\n| returns | `resource` |\n\n#### Request::file($name)\n\nLook up information about a file sent in a multipart-form request.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| returns | `array` |\n\n#### Request::files()\n\nGet information about all files sent in a multipart-form request.\n\n|   | Type |\n|---|------|\n| returns | `array[]` |\n\n#### Request::saveFile($name, $dest\\_path)\n\nSave a file uploaded as a multipart-form parameter.\n\nSaves the file uploaded under the form parameter `$name` to the path\n`$dest_path` on the filesystem.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$name`** | `string` |  |\n| **`$dest_path`** | `string` |  |\n| 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. |\n\n#### Request::originIpAddress()\n\nGet the IP address of the remote endpoint.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::originPort()\n\nGet the port number of the remote endpoint.\n\n|   | Type |\n|---|------|\n| returns | `string` |\n\n#### Request::timestamp()\n\nTimestamp of the start of the request.\n\n|   | Type |\n|---|------|\n| returns | `int` |\n\n### class Jitsu\\\\Response\n\nUtilities for building the current HTTP response about to be sent.\n\nThe class `\\Jitsu\\Http\\CurrentResponse` provides the same capabilities\nthrough an object-oriented interface. It is recommended to use that instead.\n\n#### Response::setStatus($version, $code, $reason)\n\nSet the response status line.\n\nNote that this is mutually exclusive with `code`.\n\n|   | Type |\n|---|------|\n| **`$version`** | `string` |\n| **`$code`** | `int|string` |\n| **`$reason`** | `string` |\n\n#### Response::setStatusCode($code)\n\nSet the response code.\n\nAutomatically sets an appropriate reason string.\n\nNote that this is mutually exclusive with `status`.\n\n|   | Type |\n|---|------|\n| **`$code`** | `int|string` |\n\n#### Response::statusCode()\n\nGet the currently set response code.\n\n|   | Type |\n|---|------|\n| returns | `int` |\n\n#### Response::addHeader($name, $value)\n\nSet a header in the response.\n\nMust be called before output is written, just like PHP `header`.\n\nDoes not override previously sent header with the same name.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| **`$value`** | `string` |\n\n#### Response::addCookie($name, $value, $expires = null, $path = null, $domain = null)\n\nSet a cookie in the response.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| **`$value`** | `string` |\n| **`$expires`** | `int|null` |\n| **`$path`** | `string|null` |\n| **`$domain`** | `string|null` |\n\n#### Response::deleteCookie($name, $domain = null, $path = null)\n\nIndicate in the response to delete a cookie.\n\n|   | Type |\n|---|------|\n| **`$name`** | `string` |\n| **`$domain`** | `string|null` |\n| **`$path`** | `string|null` |\n\n#### Response::redirect($url, $code)\n\nIssue an HTTP redirect.\n\n|   | Type |\n|---|------|\n| **`$url`** | `string` |\n| **`$code`** | `int|string` |\n\n#### Response::startOutputBuffering()\n\nStart buffering PHP output.\n\n#### Response::flushOutputBuffer()\n\nFlush the PHP output buffer and stop buffering.\n\n#### Response::clearOutputBuffer()\n\nDiscard the contents of the PHP output buffer and stop buffering.\n\n#### Response::sentHeaders()\n\nDetermine whether the headers were sent.\n\nIf the headers were already sent, they may no longer be modified.\n\n|   | Type |\n|---|------|\n| returns | `bool` |\n\n#### Response::bodyStream()\n\nGet a handle to a writable file stream to the response body.\n\n|   | Type |\n|---|------|\n| returns | `resource` |\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdusell%2Fjitsu-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdusell%2Fjitsu-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdusell%2Fjitsu-http/lists"}