Documentation

Mage_Core_Controller_Response_Http
in package
implements Stringable

HTTP Response class wrapping Symfony Response

Provides compatibility layer for Mage_Core_Controller_Response_Http while using Symfony HttpFoundation

Table of Contents

Interfaces

Stringable

Properties

$headersSentThrowsException  : bool
Exception thrown by action controller
$_body  : array<string|int, mixed>
Body content
$_bodyOrder  : array<string|int, mixed>
Body segment order
$_exceptions  : array<string|int, mixed>
Array of exceptions
$_headersRaw  : array<string|int, mixed>
Array of raw headers
$_headersSent  : bool
Whether headers have been emitted; Symfony sends with replace=false, so a second emission would duplicate headers instead of replacing them
$_isRedirect  : bool
Flag; is this response a redirect?
$_outputCallback  : mixed
Output callback
$_transportObject  : DataObject|null
Transport object for observers to perform
$symfonyResponse  : Response
Symfony Response instance

Methods

__construct()  : mixed
__toString()  : string
Magic __toString functionality
append()  : self
Append content to a body segment
appendBody()  : self
Append content to the body content
canSendHeaders()  : bool
Can we send headers?
clearAllHeaders()  : self
Clear all headers, normal and raw
clearBody()  : self
Clear body content
clearCookie()  : self
Clear cookie (set with past expiry)
clearHeader()  : self
Clear header by name
clearHeaders()  : self
Clear headers
clearRawHeader()  : self
Clear a specific raw header
clearRawHeaders()  : self
Clear all raw headers
finishRequest()  : void
Hand the response back to the client and release the session lock.
getBody()  : string|array<string|int, mixed>
Return the body content
getException()  : array<string|int, mixed>
Retrieve the exception stack
getExceptionByCode()  : false|Throwable
Retrieve first exception with a given code
getExceptionByMessage()  : false|Throwable
Retrieve first exception with a given message
getExceptionByType()  : false|Throwable
Retrieve first exception of given type
getExceptions()  : array<string|int, mixed>
Retrieve the exception stack (alias)
getHeaders()  : array<string|int, mixed>
Return headers as [['name' => ..., 'value' => ..., 'replace' => ...], ...] (legacy M1 format, derived from the Symfony header bag)
getHttpResponseCode()  : int
Retrieve HTTP response code
getOutputCallback()  : mixed
Get output callback
getRawHeaders()  : array<string|int, mixed>
Get all header values as an array
getSymfonyResponse()  : Response
Get the Symfony Response instance (for internal use)
hasExceptionOfCode()  : bool
Does the response object contain an exception with a given code?
hasExceptionOfMessage()  : bool
Does the response object contain an exception with a given message?
hasExceptionOfType()  : bool
Does the response object contain an exception of a given type?
hasExceptions()  : bool
Has an exception been registered with the response? (alias for isException)
hasHeader()  : bool
Whether a header is present
insert()  : self
Insert content before a named segment
isException()  : bool
Has an exception been registered with the response?
isRedirect()  : bool
Is this a redirect?
isSent()  : bool
Check if response has been sent
outputBody()  : string
Echo the body segments
prepend()  : self
Prepend content to a body segment
prependBody()  : self
Prepend content to body
sendHeaders()  : self
Send all headers
sendHeadersAndExit()  : never
Method send already collected headers and exit from script
sendJsonAndDetach()  : void
Send a JSON payload, close the connection, and keep executing in the background.
sendResponse()  : void
Send the response, including all headers
setBody()  : self
Set body content
setBodyJson()  : self
Prepare JSON formatted data for response to client
setCookie()  : self
Set cookie
setException()  : self
Register an exception with the response
setHeader()  : self
Set a header
setHttpResponseCode()  : self
Set HTTP response code to use with headers
setOutputCallback()  : self
Set output callback
setOutputOrder()  : self
Set body segment output order
setRawHeader()  : self
Set raw HTTP header
setRedirect()  : self
Set redirect URL
setRedirectUrl()  : self
Set redirect URL without exit
_normalizeHeader()  : string
Normalize a header name
deferJavaScriptLoading()  : string
Defer JavaScript loading based on selected mode
getJavaScriptDeferMode()  : int
getJavaScriptLoader()  : string
isJavaScriptTag()  : bool
Tell if a <script> tag holds code the browser executes, so it can be deferred
shouldDeferJavaScript()  : bool
Check if JavaScript deferral should be applied

Properties

$headersSentThrowsException

Exception thrown by action controller

public bool $headersSentThrowsException = \false

$_body

Body content

protected array<string|int, mixed> $_body = []

$_bodyOrder

Body segment order

protected array<string|int, mixed> $_bodyOrder = []

$_exceptions

Array of exceptions

protected array<string|int, mixed> $_exceptions = []

$_headersRaw

Array of raw headers

protected array<string|int, mixed> $_headersRaw = []

$_headersSent

Whether headers have been emitted; Symfony sends with replace=false, so a second emission would duplicate headers instead of replacing them

protected bool $_headersSent = \false

$_isRedirect

Flag; is this response a redirect?

protected bool $_isRedirect = \false

$_outputCallback

Output callback

protected mixed $_outputCallback = \null

$_transportObject

Transport object for observers to perform

protected static DataObject|null $_transportObject = \null

$symfonyResponse

Symfony Response instance

protected Response $symfonyResponse

Methods

__construct()

public __construct([array<string|int, mixed>|Response|null $args = null ]) : mixed
Parameters
$args : array<string|int, mixed>|Response|null = null

__toString()

Magic __toString functionality

public __toString() : string
Attributes
#[Override]
Return values
string

append()

Append content to a body segment

public append(string $name, string $content) : self
Parameters
$name : string
$content : string
Return values
self

appendBody()

Append content to the body content

public appendBody(string $content[, string|null $name = null ]) : self
Parameters
$content : string
$name : string|null = null
Return values
self

canSendHeaders()

Can we send headers?

public canSendHeaders([bool $throw = false ]) : bool
Parameters
$throw : bool = false
Return values
bool

clearAllHeaders()

Clear all headers, normal and raw

public clearAllHeaders() : self
Return values
self

clearBody()

Clear body content

public clearBody([string|null $name = null ]) : self
Parameters
$name : string|null = null
Return values
self

clearCookie()

Clear cookie (set with past expiry)

public clearCookie(string $name[, string $path = '/' ][, string|null $domain = null ]) : self
Parameters
$name : string
$path : string = '/'
$domain : string|null = null
Return values
self

clearHeader()

Clear header by name

public clearHeader(string $name) : self
Parameters
$name : string
Return values
self

clearHeaders()

Clear headers

public clearHeaders() : self
Return values
self

clearRawHeader()

Clear a specific raw header

public clearRawHeader(string $headerRaw) : self
Parameters
$headerRaw : string
Return values
self

clearRawHeaders()

Clear all raw headers

public clearRawHeaders() : self
Return values
self

finishRequest()

Hand the response back to the client and release the session lock.

public static finishRequest() : void

No output is allowed beyond this point. Whatever the script does next runs with the connection already closed, so concurrent requests from the same session no longer block.

getBody()

Return the body content

public getBody([bool|string $spec = false ]) : string|array<string|int, mixed>
Parameters
$spec : bool|string = false
Return values
string|array<string|int, mixed>

getException()

Retrieve the exception stack

public getException() : array<string|int, mixed>
Return values
array<string|int, mixed>

getExceptionByCode()

Retrieve first exception with a given code

public getExceptionByCode(int $code) : false|Throwable
Parameters
$code : int
Return values
false|Throwable

getExceptionByMessage()

Retrieve first exception with a given message

public getExceptionByMessage(string $message) : false|Throwable
Parameters
$message : string
Return values
false|Throwable

getExceptionByType()

Retrieve first exception of given type

public getExceptionByType(string $type) : false|Throwable
Parameters
$type : string
Return values
false|Throwable

getExceptions()

Retrieve the exception stack (alias)

public getExceptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHeaders()

Return headers as [['name' => ..., 'value' => ..., 'replace' => ...], ...] (legacy M1 format, derived from the Symfony header bag)

public getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHttpResponseCode()

Retrieve HTTP response code

public getHttpResponseCode() : int
Return values
int

getOutputCallback()

Get output callback

public getOutputCallback() : mixed

getRawHeaders()

Get all header values as an array

public getRawHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSymfonyResponse()

Get the Symfony Response instance (for internal use)

public getSymfonyResponse() : Response
Return values
Response

hasExceptionOfCode()

Does the response object contain an exception with a given code?

public hasExceptionOfCode(int $code) : bool
Parameters
$code : int
Return values
bool

hasExceptionOfMessage()

Does the response object contain an exception with a given message?

public hasExceptionOfMessage(string $message) : bool
Parameters
$message : string
Return values
bool

hasExceptionOfType()

Does the response object contain an exception of a given type?

public hasExceptionOfType(string $type) : bool
Parameters
$type : string
Return values
bool

hasExceptions()

Has an exception been registered with the response? (alias for isException)

public hasExceptions() : bool
Return values
bool

hasHeader()

Whether a header is present

public hasHeader(string $name) : bool
Parameters
$name : string
Return values
bool

insert()

Insert content before a named segment

public insert(string $name, string $content[, string|null $parent = null ][, bool $before = false ]) : self
Parameters
$name : string
$content : string
$parent : string|null = null
$before : bool = false
Return values
self

isException()

Has an exception been registered with the response?

public isException() : bool
Return values
bool

isRedirect()

Is this a redirect?

public isRedirect() : bool
Return values
bool

isSent()

Check if response has been sent

public isSent() : bool
Return values
bool

outputBody()

Echo the body segments

public outputBody() : string
Return values
string

prepend()

Prepend content to a body segment

public prepend(string $name, string $content) : self
Parameters
$name : string
$content : string
Return values
self

prependBody()

Prepend content to body

public prependBody(string $content[, string|null $name = null ]) : self
Parameters
$content : string
$name : string|null = null
Return values
self

sendHeaders()

Send all headers

public sendHeaders() : self

Emission is delegated to the wrapped Symfony response, so ResponseHeaderBag defaults (conservative Cache-Control, Date) apply. The response is prepared against the current request first (RFC compliance: Content-Type charset, HEAD/304 body stripping, protocol version, secure cookies). Raw headers are sent after preparation and suppress any same-named header from the bag.

Return values
self

sendHeadersAndExit()

Method send already collected headers and exit from script

public sendHeadersAndExit() : never
Return values
never

sendJsonAndDetach()

Send a JSON payload, close the connection, and keep executing in the background.

public sendJsonAndDetach(mixed $data) : void

Lets an action hand the client a handle (a token, an id) for a job that takes far longer than any request timeout allows. The caller must not emit anything afterwards; exit() once the work is done unless the rest of App::run() still has to happen.

Parameters
$data : mixed

sendResponse()

Send the response, including all headers

public sendResponse() : void

setBody()

Set body content

public setBody(string $content[, string|null $name = null ]) : self
Parameters
$content : string
$name : string|null = null
Return values
self

setBodyJson()

Prepare JSON formatted data for response to client

public setBodyJson(mixed $response) : self
Parameters
$response : mixed
Return values
self

setCookie()

Set cookie

public setCookie(string $name[, string $value = '' ][, int $lifetime = 0 ][, string $path = '/' ][, string|null $domain = null ][, bool $secure = false ][, bool $httponly = false ]) : self
Parameters
$name : string
$value : string = ''
$lifetime : int = 0
$path : string = '/'
$domain : string|null = null
$secure : bool = false
$httponly : bool = false
Return values
self

setException()

Register an exception with the response

public setException(Throwable $e) : self
Parameters
$e : Throwable
Return values
self

setHeader()

Set a header

public setHeader(string $name, string $value[, bool $replace = true ]) : self
Parameters
$name : string
$value : string
$replace : bool = true
Return values
self

setHttpResponseCode()

Set HTTP response code to use with headers

public setHttpResponseCode(int $code) : self
Parameters
$code : int
Return values
self

setOutputCallback()

Set output callback

public setOutputCallback(mixed $callback) : self
Parameters
$callback : mixed
Return values
self

setOutputOrder()

Set body segment output order

public setOutputOrder(array<string|int, mixed> $order) : self
Parameters
$order : array<string|int, mixed>
Return values
self

setRawHeader()

Set raw HTTP header

public setRawHeader(string $value) : self
Parameters
$value : string
Return values
self

setRedirect()

Set redirect URL

public setRedirect(string $url[, int $code = 302 ]) : self

Sets Location header and response code. Forces replacement of any prior redirects.

Parameters
$url : string
$code : int = 302
Return values
self

setRedirectUrl()

Set redirect URL without exit

public setRedirectUrl(string $url) : self
Parameters
$url : string
Return values
self

_normalizeHeader()

Normalize a header name

protected _normalizeHeader(string $name) : string
Parameters
$name : string
Return values
string

deferJavaScriptLoading()

Defer JavaScript loading based on selected mode

protected deferJavaScriptLoading(string $html, int $mode) : string
Parameters
$html : string
$mode : int
Return values
string

getJavaScriptDeferMode()

protected getJavaScriptDeferMode() : int
Return values
int

getJavaScriptLoader()

protected getJavaScriptLoader() : string
Return values
string

isJavaScriptTag()

Tell if a <script> tag holds code the browser executes, so it can be deferred

protected isJavaScriptTag(string $tag) : bool
Parameters
$tag : string
Return values
bool

shouldDeferJavaScript()

Check if JavaScript deferral should be applied

protected shouldDeferJavaScript(string $body) : bool
Parameters
$body : string
Return values
bool
On this page

Search results