Skip to content

Core\Response

The response your program sends back to a request. sendHtml(), sendText(), sendJson(), sendBytes(), sendFile() and startStream() write the body, and each one sets the matching Content-Type. setStatus(), setHeader(), redirect() and addCookie() change the status line and the headers.

Members

11 members.

MemberSignature
sendHtmlsendHtml(Core\Html\Markup $body): void
sendJsonsendJson(mixed $value): void
sendTextsendText(string $body): void
sendBytessendBytes(bytes $body, string $contentType): void
sendFilesendFile(string $path): void
startStreamstartStream(string $contentType, ?int $length = null, ?string $etag = null, ?string $mustEnd = null): Core\Response\Stream
setStatussetStatus(uint $code): void
sendSlottedsendSlotted(): void
setHeadersetHeader(string $name, string $value): void
redirectredirect(string $url, Core\Response::Redirect $status = Core\Response::Redirect::SeeOther): void
addCookieaddCookie(string $name, string $value, { secure?: bool, httpOnly?: bool, sameSite?: Core\Response::SameSite, path?: string, domain?: string, maxAge?: Core\Time\Duration }): void

Enums

  • RedirectThe kind of redirect a response sends. Every browser handles these three statuses in the same way, so the browser does exactly what your program says.
  • SameSiteWhich requests from other sites send a cookie. The three cases are the values of the cookie's SameSite attribute. The default is Lax. A cookie that is sent with requests from other sites makes a CSRF attack possible.

Example apps

These complete apps use this class. You can download and run each one.

  • Notes: A small notes app with SQLite, HTML pages, a JSON API, form checks and tests. Download it, run it and start your own app from it.
  • Poll: A live poll with SQLite and server-sent events. Every open page shows each new vote at once, with no extra server and no library.