Skip to content

HttpHeader

Raxos\Http\HttpHeader

A final class of string constants for well known HTTP header names. Using these constants instead of hardcoded strings turns a typo into a compile time error and keeps header naming consistent across the package.

php
final class HttpHeader

Constants

Every constant is a lowercase header name, matching the way HttpHeadersMap normalizes its keys. The class covers permanent, provisional and non-standard headers. A selection:

ConstantValue
HttpHeader::ACCEPTaccept
HttpHeader::ACCEPT_LANGUAGEaccept-language
HttpHeader::AUTHORIZATIONauthorization
HttpHeader::CACHE_CONTROLcache-control
HttpHeader::CONTENT_DISPOSITIONcontent-disposition
HttpHeader::CONTENT_TYPEcontent-type
HttpHeader::LOCATIONlocation
HttpHeader::USER_AGENTuser-agent
HttpHeader::X_FORWARDED_FORx-forwarded-for

Refer to the source for the full list of constants.

Example

php
<?php
declare(strict_types=1);

use Raxos\Http\HttpHeader;
use Raxos\Http\Response\JsonHttpResponse;

$response = new JsonHttpResponse(['status' => 'ok']);
$response->header(HttpHeader::CACHE_CONTROL, 'no-store', replace: true);

The constants also pair with the header map on a request:

php
use Raxos\Http\HttpRequest;

$request = HttpRequest::createFromGlobals();
$agent = $request->headers->get(HttpHeader::USER_AGENT);