File src/class/Http/Response.php

class Lia\Http\Response

Mutable object to represent a web response

Constants

Properties

  • public \Lia\Http\Request $request; The request being responded to.
  • public string $body = ''; The body to send
  • public string $theme_name; A theme in your app, or from an app you depend on.
    Or a built-in theme:
  • raw: send body, default.
  • html_page: wrap content in valid html with doctype, head, body, with automatic css & js inclusion.
  • json (placeholder for apps and routes that optionally return json)
  • public array $headers = []; Array of headers, where each header is an array arglist to past to header()

Headers can also just be sent directly

Example:
[
['Location: /url/', true, 302],
]
or
[
['Last-Modified: Sun, 10 Dec 2023 04:02:06', true, 304],
['Content-type: text/json');
['Content-Length: 502');
['Cache-Control: max-age=2592000'); // 2592000 is 30 days
]

  • public bool $send_body = true; Whether to send content or not. Mark false if you're sending headers to load-from-cache

Methods

  • public function __construct(\Lia\Http\Request $request)

  • public function addHeader(array $header) Add a header.

  • public function redirect_temporary(string $url) Add a header to redirect to url with 302 status code for temporary redirect.

  • public function redirect_permantent(string $url) Add a header to redirect to url with 301 status code for Moved Permanently

  • public function addHeaders($headers) Add multiple headers.

  • public function sendHeaders() Send headers by calling header()
    To override the call to header() implement a function \Lia\Http\header(...) which takes the same args.

  • public function send() Send headers & body.

If $this->send_body is set false, body will not be sent.

  • public function PageNotFound() Add the header: HTTP/1.1 404 Not Found
  • public function InternalServerError() Add the header: HTTP/1.1 500 Internal Server Error