class HTTPStreamResponse extends HTTPResponse (View source)

A response which contains a streamable data source.

Traits

A class that can be instantiated or replaced via DI

Properties

protected static array $status_codes from  HTTPResponse
protected static array $redirect_codes from  HTTPResponse
protected string $protocolVersion from  HTTPResponse
protected int $statusCode from  HTTPResponse
protected string $statusDescription from  HTTPResponse
protected array $headers

HTTP Headers like "content-type: text/xml"

from  HTTPResponse
protected string $body from  HTTPResponse
protected resource $stream

Stream source for this response

protected bool $consumed

Set to true if this stream has been consumed.

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(resource $stream, int $contentLength, int $statusCode = null, string $statusDescription = null)

HTTPStreamResponse constructor.

public
$this
setProtocolVersion(string $protocolVersion)

The HTTP version used to respond to this request (typically 1.0 or 1.1)

public
$this
setStatusCode(int $code, string $description = null)

No description

public
$this
setStatusDescription(string $description)

The text to be given alongside the status code ("reason phrase").

public
string
getProtocolVersion()

No description

public
int
getStatusCode()

No description

public
string
getStatusDescription()

No description

public
bool
isError()

Returns true if this HTTP response is in error

public
$this
setBody(string $body)

No description

public
string
getBody()

No description

public
$this
addHeader(string $header, string $value)

Add a HTTP header to the response, replacing any header of the same name.

public
string
getHeader(string $header)

Return the HTTP header of the given name.

public
array
getHeaders()

No description

public
$this
removeHeader(string $header)

Remove an existing HTTP header by its name, e.g. "Content-Type".

public
redirect(string $dest, int $code = 302)

No description

public
output()

Send this HTTPResponse to the browser

protected
htmlRedirect()

Generate a browser redirect without setting headers

protected
outputHeaders()

Output HTTP headers to the browser

protected
outputBody()

Output body of this response to the browser

public
bool
isFinished()

Returns true if this response is "finished", that is, no more script execution should be done.

public
bool
isRedirect()

Determine if this response is a redirect

public
string
__toString()

The HTTP response represented as a raw string

protected
bool
isSeekable()

Determine if a stream is seekable

public
resource
getStream()

No description

public
$this
setStream(resource $stream)

No description

public
string
getSavedBody()

Get body prior to stream traversal

protected
mixed
consumeStream(callable $callback)

Safely consume the stream

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(resource $stream, int $contentLength, int $statusCode = null, string $statusDescription = null)

HTTPStreamResponse constructor.

Parameters

resource $stream

Data stream

int $contentLength

size of the stream in bytes

int $statusCode

The numeric status code - 200, 404, etc

string $statusDescription

The text to be given alongside the status code. See setStatusCode() for more information.

$this setProtocolVersion(string $protocolVersion)

The HTTP version used to respond to this request (typically 1.0 or 1.1)

Parameters

string $protocolVersion

Return Value

$this

$this setStatusCode(int $code, string $description = null)

No description

Parameters

int $code
string $description

Optional. See setStatusDescription(). No newlines are allowed in the description. If omitted, will default to the standard HTTP description for the given $code value (see $status_codes).

Return Value

$this

$this setStatusDescription(string $description)

The text to be given alongside the status code ("reason phrase").

Caution: Will be overwritten by setStatusCode().

Parameters

string $description

Return Value

$this

string getProtocolVersion()

No description

Return Value

string

int getStatusCode()

No description

Return Value

int

string getStatusDescription()

No description

Return Value

string

Description for a HTTP status code

bool isError()

Returns true if this HTTP response is in error

Return Value

bool

$this setBody(string $body)

No description

Parameters

string $body

Return Value

$this

string getBody()

No description

Return Value

string

$this addHeader(string $header, string $value)

Add a HTTP header to the response, replacing any header of the same name.

Parameters

string $header

Example: "content-type"

string $value

Example: "text/xml"

Return Value

$this

string getHeader(string $header)

Return the HTTP header of the given name.

Parameters

string $header

Return Value

string

array getHeaders()

No description

Return Value

array

$this removeHeader(string $header)

Remove an existing HTTP header by its name, e.g. "Content-Type".

Parameters

string $header

Return Value

$this

HTTPResponse redirect(string $dest, int $code = 302)

No description

Parameters

string $dest
int $code

Return Value

HTTPResponse

output()

Send this HTTPResponse to the browser

protected htmlRedirect()

Generate a browser redirect without setting headers

protected outputHeaders()

Output HTTP headers to the browser

protected outputBody()

Output body of this response to the browser

bool isFinished()

Returns true if this response is "finished", that is, no more script execution should be done.

Specifically, returns true if a redirect has already been requested

Return Value

bool

bool isRedirect()

Determine if this response is a redirect

Return Value

bool

string __toString()

The HTTP response represented as a raw string

Return Value

string

protected bool isSeekable()

Determine if a stream is seekable

Return Value

bool

resource getStream()

No description

Return Value

resource

$this setStream(resource $stream)

No description

Parameters

resource $stream

Return Value

$this

string getSavedBody()

Get body prior to stream traversal

Return Value

string

protected mixed consumeStream(callable $callback)

Safely consume the stream

Parameters

callable $callback

Callback which will perform the consumable action on the stream

Return Value

mixed

Result of $callback($stream) or null if no stream available

Exceptions

BadMethodCallException