class Response

Class that represents an HTTP 1.0 / 1.1 response message.

Methods

__construct(int $status, array $headers, string $body = null, string $version = '1.1', string $message = null)

Constructor.

bool
isSuccessful()

Check whether the response in successful

bool
isError()

Check whether the response is an error

bool
isRedirect()

Check whether the response is a redirection

int
getStatus()

Get the HTTP response status code

string
getMessage()

Return a message describing the HTTP response code (Eg. "OK", "Not Found", "Moved Permanently")

string
getBody()

Get the response body as string

string
getRawBody()

Get the raw response body (as transfered "on wire") as string

string
getVersion()

Get the HTTP version of the response

array
getHeaders()

Get the response headers

string|array|null
getHeader(string $header)

Get a specific header as string, or null if it is not set

string
getHeadersAsString(bool $statusLine = true, string $br = "\n")

Get all headers as string

static Response
fromString(string $responseStr)

Create an EasyRdf\Http\Response object from a HTTP response string

static string
decodeChunkedBody(string $body)

Decode a "chunked" transfer-encoded body and return the decoded text

static string
decodeGzip(string $body)

Decode a gzip encoded message (when Content-encoding = gzip)

static string
decodeDeflate(string $body)

Decode a zlib deflated message (when Content-encoding = deflate)

string
asString(string $br = "\n")

Get the entire response as string

string
__toString()

Implements magic __toString()

Details

at line 92
__construct(int $status, array $headers, string $body = null, string $version = '1.1', string $message = null)

Constructor.

Parameters

int $status HTTP Status code
array $headers The HTTP response headers
string $body The content of the response
string $version The HTTP Version (1.0 or 1.1)
string $message The HTTP response Message

at line 115
bool isSuccessful()

Check whether the response in successful

Return Value

bool

at line 125
bool isError()

Check whether the response is an error

Return Value

bool

at line 135
bool isRedirect()

Check whether the response is a redirection

Return Value

bool

at line 145
int getStatus()

Get the HTTP response status code

Return Value

int

at line 156
string getMessage()

Return a message describing the HTTP response code (Eg. "OK", "Not Found", "Moved Permanently")

Return Value

string

at line 166
string getBody()

Get the response body as string

Return Value

string

at line 193
string getRawBody()

Get the raw response body (as transfered "on wire") as string

If the body is encoded (with Transfer-Encoding, not content-encoding - IE "chunked" body), gzip compressed, etc. it will not be decoded.

Return Value

string

at line 203
string getVersion()

Get the HTTP version of the response

Return Value

string

at line 213
array getHeaders()

Get the response headers

Return Value

array

at line 225
string|array|null getHeader(string $header)

Get a specific header as string, or null if it is not set

Parameters

string $header

Return Value

string|array|null

at line 243
string getHeadersAsString(bool $statusLine = true, string $br = "\n")

Get all headers as string

Parameters

bool $statusLine Whether to return the first status line (ie "HTTP 200 OK")
string $br Line breaks (eg. "\n", "\r\n", "
")

Return Value

string

at line 273
static Response fromString(string $responseStr)

Create an EasyRdf\Http\Response object from a HTTP response string

Parameters

string $responseStr

Return Value

Response

Exceptions

Exception

at line 329
static string decodeChunkedBody(string $body)

Decode a "chunked" transfer-encoded body and return the decoded text

Parameters

string $body

Return Value

string

Exceptions

Exception

at line 359
static string decodeGzip(string $body)

Decode a gzip encoded message (when Content-encoding = gzip)

Currently requires PHP with zlib support

Parameters

string $body

Return Value

string

Exceptions

Exception

at line 381
static string decodeDeflate(string $body)

Decode a zlib deflated message (when Content-encoding = deflate)

Currently requires PHP with zlib support

Parameters

string $body

Return Value

string

Exceptions

Exception

at line 417
string asString(string $br = "\n")

Get the entire response as string

Parameters

string $br Line breaks (eg. "\n", "\r\n", "
")

Return Value

string

at line 427
string __toString()

Implements magic __toString()

Return Value

string