Http
The Http package provides Quantum's concrete request and response objects plus a small helper layer around them.
At package level, it is built from two runtime objects:
Quantum\Http\Requestfor inbound method, URL, headers, input data, uploaded files, and matched-route metadataQuantum\Http\Responsefor outbound status, headers, redirects, and body formatting
It also ships:
Quantum\Http\Helpers\http.phpglobal helpers such asrequest(),response(),redirect(), andold()Quantum\Http\Enums\ContentTypeandQuantum\Http\Enums\StatusCodeconstant setsQuantum\Http\Exceptions\HttpExceptionfor package-specific runtime failures
Shared-instance model
Both request() and response() are DI-backed helpers.
On first use, each helper registers its class in the container and then returns Di::get(...). Repeated helper calls therefore reuse one shared Request instance and one shared Response instance for the current container.
That matters because later mutations operate on the same objects:
request()->set(...)changes the shared request payloadresponse()->json(...)keeps building the same response object until it is flushed or replaced
Request bootstrap model
Request::__construct() accepts an optional Quantum\Environment\Server instance. If none is passed, it resolves server() and immediately calls populateFromServer().
populateFromServer() does four things in order:
- copies method, protocol, host, port, URI, and query string from the server object
- reads a normalized content type from the server object
- loads request headers from
getallheaders()and lowercases the keys - parses request parameters and files, including raw multipart bodies when needed
The final request parameter store is merged in this order:
- filtered
$_GET - filtered
$_POST - JSON body payload for
PUT,PATCH, orPOSTwithapplication/json - URL-encoded raw body for
PUT,PATCH, orPOSTwithapplication/x-www-form-urlencoded - parsed multipart raw input parameters
Later sources overwrite earlier ones when keys collide.
Response formatting model
Response keeps a status code, a header map, and an internal response array.
Body formatting is content-type-driven:
text/html-> rendered view stringapplication/json->json_encode($responseData)application/xml-> array-to-XML conversionapplication/javascript-> JSONP callback wrapping
If the current Content-Type does not match one of those formatters, getContent() throws HttpException.
Important package constraints
Request::METHODSonly allowsGET,POST,PUT,PATCH, andDELETE.Request::flush()clears headers, payload, files, protocol, host, port, URI, and query, but it does not clear the matched route object.Response::send()emits headers and the formatted body directly; it does not return the content.redirect()only sets status andLocation; it does not build a body automatically.page_not_found_response()treats the request as JSON only when theAcceptheader is exactlyapplication/json.