API Index — Namespaces, Packages, Reports, Indices
Response
in package
Thin wrapper around \OpenSwoole\Http\Response. The __call / __get /
__set proxies forward to the underlying response — these @method
annotations expose the forwarded signatures to static analysis so call
sites are statically typed instead of treated as mixed.
Table of Contents
Constants
- MAX_RANGES : mixed = 200
- Maximum number of comma-separated range specs honoured in a single Range header. Mirrors Apache's AP_DEFAULT_MAX_RANGES (byterange_filter.c).
- REDIRECT_REASONS : mixed = [301 => 'Moved Permanently', 302 => 'Found', 30...
Properties
- $cookiesList : array<int, array{0: string, 1: string, 2: int, 3: string, 4: string, 5: bool, 6: bool, 7: string, 8: string}>
- $headersList : array<int, array{0: string, 1: string}>
- $parent : Response
- $rawCookiesList : array<int, array{0: string, 1: string, 2: int, 3: string, 4: string, 5: bool, 6: bool, 7: string, 8: string}>
- $g : RequestContext
- $htmxBuilder : HtmxResponse|null
- $statusCode : int|null
Methods
- __call() : mixed
- Forward method calls to the underlying OpenSwoole response.
- __construct() : mixed
- __get() : mixed
- Proxy property reads to the underlying OpenSwoole response.
- __set() : mixed
- Proxy property writes to the underlying OpenSwoole response.
- close() : void
- cookie() : bool
- create() : Response|false
- detach() : bool
- end() : bool
- flush() : bool
- header() : bool
- htmx() : HtmxResponse
- Returns a fluent HtmxResponse builder that queues HX-* headers into this response. Each call returns the same builder instance (one per Response object) so callers can chain or call multiple times.
- isWritable() : bool
- json() : void
- Emit a JSON response and end the connection.
-
parseRange()
: array{status: "ignore"|"unsatisfiable"|"ok", ranges: array
} - Parse a Range header value into a normalised list of [start, end] byte ranges (inclusive, clamped to the resource size).
- push() : bool
- rawCookie() : bool
- recv() : bool
- redirect() : void
- Send an HTTP redirect.
- sendfile() : int|false
- sendFile() : void
- Serve a file with Range request support using OpenSwoole's zero-copy sendfile.
- sse() : void
- Server-Sent Events endpoint. Sets the required headers and delegates to stream(). The $fn callback receives an $emit() closure: $emit(string $data, string $event = '', string $id = '') which formats and sends one SSE message.
- status() : bool
- stream() : void
- Stream a response body in chunks. Headers are flushed immediately.
- trailer() : bool
- upgrade() : void
- write() : bool
- ifRangeMatches() : bool
- Evaluate an If-Range header value against the resource's validators.
- sendMultipart() : void
- Emit a 206 multipart/byteranges response for two or more ranges, streaming each slice straight from the file. Body framing mirrors RangeMiddleware so both paths produce byte-identical multipart output.
Constants
MAX_RANGES
Maximum number of comma-separated range specs honoured in a single Range header. Mirrors Apache's AP_DEFAULT_MAX_RANGES (byterange_filter.c).
private
mixed
MAX_RANGES
= 200
Beyond this the Range header is ignored and the full body is served (200), matching Apache's CVE-2011-3192 mitigation.
REDIRECT_REASONS
private
mixed
REDIRECT_REASONS
= [301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect']
Properties
$cookiesList
public
array<int, array{0: string, 1: string, 2: int, 3: string, 4: string, 5: bool, 6: bool, 7: string, 8: string}>
$cookiesList
= []
$headersList
public
array<int, array{0: string, 1: string}>
$headersList
= []
$parent
public
Response
$parent
$rawCookiesList
public
array<int, array{0: string, 1: string, 2: int, 3: string, 4: string, 5: bool, 6: bool, 7: string, 8: string}>
$rawCookiesList
= []
$g
private
RequestContext
$g
$htmxBuilder
private
HtmxResponse|null
$htmxBuilder
= null
$statusCode
private
int|null
$statusCode
= null
Methods
__call()
Forward method calls to the underlying OpenSwoole response.
public
__call(string $name, array<int, mixed> $arguments) : mixed
Parameters
- $name : string
- $arguments : array<int, mixed>
__construct()
public
__construct(Response $response) : mixed
Parameters
- $response : Response
__get()
Proxy property reads to the underlying OpenSwoole response.
public
& __get(string $name) : mixed
Parameters
- $name : string
__set()
Proxy property writes to the underlying OpenSwoole response.
public
__set(string $name, mixed $value) : mixed
Parameters
- $name : string
- $value : mixed
close()
public
close() : void
cookie()
public
cookie(string $key[, string $value = '' ][, int $expire = 0 ][, string $path = '/' ][, string $domain = '' ][, bool $secure = false ][, bool $httponly = false ][, string $samesite = '' ][, string $priority = '' ]) : bool
Parameters
- $key : string
- $value : string = ''
- $expire : int = 0
- $path : string = '/'
- $domain : string = ''
- $secure : bool = false
- $httponly : bool = false
- $samesite : string = ''
- $priority : string = ''
Return values
boolcreate()
public
static create([int $fd = = '-1' ]) : Response|false
Parameters
- $fd : int = = '-1'
Return values
Response|falsedetach()
public
detach() : bool
Return values
boolend()
public
end([string|null $data = null ]) : bool
Parameters
- $data : string|null = null
Return values
boolflush()
public
flush() : bool
Return values
boolheader()
public
header(string $key, string $value) : bool
Parameters
- $key : string
- $value : string
Return values
boolhtmx()
Returns a fluent HtmxResponse builder that queues HX-* headers into this response. Each call returns the same builder instance (one per Response object) so callers can chain or call multiple times.
public
htmx() : HtmxResponse
Return values
HtmxResponseisWritable()
public
isWritable() : bool
Return values
booljson()
Emit a JSON response and end the connection.
public
json(mixed $data[, int $status = 200 ]) : void
Parameters
- $data : mixed
- $status : int = 200
parseRange()
Parse a Range header value into a normalised list of [start, end] byte ranges (inclusive, clamped to the resource size).
public
static parseRange(string $rangeHeader, int $total) : array{status: "ignore"|"unsatisfiable"|"ok", ranges: array}
Mirrors RangeMiddleware's spec handling so both the buffered and the zero-copy file paths agree on suffix / open-end / bounded semantics.
Returns one of:
- ['status' => 'ignore', 'ranges' => []]
Header is not a
bytes=range, contains a syntactically invalid spec (RFC 7233 §2.1: an invalid spec invalidates the whole header), or the range count exceeds MAX_RANGES (CVE-2011-3192 mitigation). Caller serves the full body (200). - ['status' => 'unsatisfiable', 'ranges' => []] Every well-formed spec is out of bounds (416).
- ['status' => 'ok', 'ranges' => array<int, array{0: int, 1: int}>]
Parameters
- $rangeHeader : string
- $total : int
Return values
array{status: "ignore"|"unsatisfiable"|"ok", ranges: arraypush()
public
push(string $filename[, int $opcode = = '1' ][, bool $finish = = 'true' ]) : bool
Parameters
- $filename : string
- $opcode : int = = '1'
- $finish : bool = = 'true'
Return values
boolrawCookie()
public
rawCookie(string $key[, string $value = '' ][, int $expire = 0 ][, string $path = '/' ][, string $domain = '' ][, bool $secure = false ][, bool $httponly = false ][, string $samesite = '' ][, string $priority = '' ]) : bool
Parameters
- $key : string
- $value : string = ''
- $expire : int = 0
- $path : string = '/'
- $domain : string = ''
- $secure : bool = false
- $httponly : bool = false
- $samesite : string = ''
- $priority : string = ''
Return values
boolrecv()
public
recv([float $timeout = = '0' ]) : bool
Parameters
- $timeout : float = = '0'
Return values
boolredirect()
Send an HTTP redirect.
public
redirect(string $url[, int $status = 302 ]) : void
Parameters
- $url : string
-
Destination URL (absolute or relative)
- $status : int = 302
-
301 Moved Permanently, 302 Found (default), 307 Temporary Redirect, 308 Permanent Redirect
sendfile()
public
sendfile(string $filename[, int $offset = = '0' ][, int $length = = '0' ]) : int|false
Parameters
- $filename : string
- $offset : int = = '0'
- $length : int = = '0'
Return values
int|falsesendFile()
Serve a file with Range request support using OpenSwoole's zero-copy sendfile.
public
sendFile(string $path[, string $filename = '' ]) : void
Parameters
- $path : string
-
Absolute path to the file
- $filename : string = ''
-
Optional download filename (triggers Content-Disposition: attachment)
sse()
Server-Sent Events endpoint. Sets the required headers and delegates to stream(). The $fn callback receives an $emit() closure: $emit(string $data, string $event = '', string $id = '') which formats and sends one SSE message.
public
sse(callable $fn) : void
Parameters
- $fn : callable
status()
public
status(int $statusCode[, string $reason = '' ]) : bool
Parameters
- $statusCode : int
- $reason : string = ''
Return values
boolstream()
Stream a response body in chunks. Headers are flushed immediately.
public
stream(callable $fn) : void
The $fn callback receives a $write(string $chunk) closure; call it for each piece of content. The response is closed when $fn returns.
Use inside a coroutine route — co::sleep() or channel ops between $write() calls yield the event loop so other requests aren't blocked.
Parameters
- $fn : callable
trailer()
public
trailer(string $key, string $value) : bool
Parameters
- $key : string
- $value : string
Return values
boolupgrade()
public
upgrade() : void
write()
public
write(string $content) : bool
Parameters
- $content : string
Return values
boolifRangeMatches()
Evaluate an If-Range header value against the resource's validators.
private
ifRangeMatches(string $ifRange, string $etag, int $mtime) : bool
Parameters
- $ifRange : string
-
Raw If-Range header value
- $etag : string
-
The resource's current ETag (entity-tag form)
- $mtime : int
-
The resource's last-modified time (unix seconds)
Return values
bool —true → the validator still matches, honour the Range
sendMultipart()
Emit a 206 multipart/byteranges response for two or more ranges, streaming each slice straight from the file. Body framing mirrors RangeMiddleware so both paths produce byte-identical multipart output.
private
sendMultipart(string $path, array<int, array{0: int, 1: int}> $ranges, int $total, string $mime) : void
Parameters
- $path : string
- $ranges : array<int, array{0: int, 1: int}>
- $total : int
- $mime : string