1.2.4. Headers

The header field labels are retained internally in lower-case. This is to comply with HTTP/2 requirements; while HTTP/1.x has no such requirement, lower-case is also recognized as valid.

Further, the header field values are retained and returned as Sapien\Request\Header objects, not strings.

1.2.4.1. Setting

1.2.4.1.1. Setting One Header

final public setHeader(string $label, Header|string $value) : static

Overwrites the $label HTTP header in the Response; a buffered equivalent of header("$label: $value", true).

The method is fluent, allowing you to chain a call to another Response method.

1.2.4.1.2. Setting All Headers

final public setHeaders(array $headers) : static

Overwrites all previous headers on the Response, replacing them with the new $headers array. Each $headers element key is the field label, and the corresponding element value is the field value.

The method is fluent, allowing you to chain a call to another Response method.

1.2.4.2. Adding

final public addHeader(string $label, Header|string $value) : static

Appends to the $label HTTP header in the Response, comma-separating it from the existing value; a buffered equivalent of header("$label: $value", false).

The method is fluent, allowing you to chain a call to another Response method.

1.2.4.3. Getting

1.2.4.3.1. Getting One Header

final public getHeader(string $label) : ?Header

Returns the $label header from the Response, if it exists.

1.2.4.3.2. Getting All Headers

final public getHeaders() : array

Returns the array of Header objects in the Response.

1.2.4.4. Checking

final public hasHeader(string $label) : bool

Returns true if the $label header exists in the Response, false if not.

1.2.4.5. Removing

1.2.4.5.1. Removing One Header

final public unsetHeader(string $label) : static

Removes the $label header from the Response.

The method is fluent, allowing you to chain a call to another Response method.

1.2.4.5.2. Removing All Headers

final public unsetHeaders() : static

Removes all headers from the buffer.

The method is fluent, allowing you to chain a call to another Response method.