HtmlResponse

Class
extends Response
Final: Yes

Class HtmlResponse.

Description

Represents an HTTP response containing HTML content.

This class MUST be used to generate HTTP responses with a text/html content type. It automatically sets the 'Content-Type' header, encodes the body using the specified charset, and applies the HTTP 200 (OK) status code by default.

Table of Contents

Methods

__construct()

Constructs a new HtmlResponse instance.

 : mixed
Methods

__construct()

Public

Constructs a new HtmlResponse instance.

public __construct( string  $html[, string  $charset = 'utf-8'][, array<string|int, mixed>  $headers = []]) : mixed

Description

This constructor SHALL set the 'Content-Type' header to text/html with the specified charset and initialize the response body with the provided HTML content. The response status code will be set to 200 (OK) by default, with the corresponding reason phrase.

Parameters
$html : string

Description

the HTML content to send in the response body

$charset : string = 'utf-8'

Description

The character encoding to declare in the 'Content-Type' header. Defaults to 'utf-8'.

$headers : array<string|int, mixed> = []

Description

optional additional headers to include in the response