class HttpMessage implements Countable, Serializable, Iterator (View source)

Constants

TYPE_NONE

TYPE_REQUEST

TYPE_RESPONSE

Properties

protected $type
protected $body
protected $requestMethod
protected $requestUrl
protected $responseStatus
protected $responseCode
protected $httpVersion
protected $headers
protected $parentMessage

Methods

__construct(string $message = null)

(PECL pecl_http >= 0.10.0)
HttpMessage constructor

string
getBody()

(PECL pecl_http >= 0.10.0)
Get message body

void
setBody(string $body)

(PECL pecl_http >= 0.14.0)
Set message body

string|null
getHeader(string $header)

(PECL pecl_http >= 1.1.0)
Get header

array
getHeaders()

(PECL pecl_http >= 0.10.0)
Get message headers

void
setHeaders(array $header)

(PECL pecl_http >= 0.10.0)
Set headers

void
addHeaders(array $headers, bool $append = null)

(PECL pecl_http >= 0.10.0)
Add headers

int
getType()

(PECL pecl_http >= 0.10.0)
Get message type

void
setType(int $type)

(PECL pecl_http >= 0.10.0)
Set message type

getInfo()

No description

setInfo($http_info)

No description

int|false
getResponseCode()

(PECL pecl_http >= 0.10.0)
Get response code

bool
setResponseCode(int $code)

(PECL pecl_http >= 0.10.0)
Set response code

string
getResponseStatus()

(PECL pecl_http >= 0.23.0)
Get response status

bool
setResponseStatus(string $status)

(PECL pecl_http >= 0.23.0)
Set response status

string|false
getRequestMethod()

(PECL pecl_http >= 0.10.0)
Get request method

bool
setRequestMethod(string $method)

(PECL pecl_http >= 0.10.0)
Set request method

string|false
getRequestUrl()

(PECL pecl_http >= 0.21.0)
Get request URL

bool
setRequestUrl(string $url)

(PECL pecl_http >= 0.21.0)
Set request URL

string
getHttpVersion()

(PECL pecl_http >= 0.10.0)
Get HTTP version

bool
setHttpVersion(string $version)

(PECL pecl_http >= 0.10.0)
Set HTTP version

string|false
guessContentType(string $magic_file, int $magic_mode = null)

(PECL pecl_http >= 1.0.0)
Guess content type

getParentMessage()

(PECL pecl_http >= 0.10.0)
Get parent message

bool
send()

(PECL pecl_http >= 0.10.0)
Send message

string
toString(bool $include_parent = null)

(PECL pecl_http >= 0.10.0)
Get string representation

toMessageTypeObject()

(PECL pecl_http >= 0.22.0)
Create HTTP object regarding message type

int
count()

Count elements of an object

string|null
serialize()

String representation of object.

void
unserialize($serialized)

No description

void
rewind()

Rewind the Iterator to the first element

bool
valid()

Checks if current position is valid

mixed
current()

Return the current element

mixed
key()

Return the key of the current element

void
next()

Move forward to next element

string
__toString()

No description

static HttpMessage|null
factory(string $raw_message = null, string $class_name = null)

(PECL pecl_http >= 1.4.0)
Create HttpMessage from string

static HttpMessage|null
fromString(string $raw_message = null, string $class_name = null)

(PECL pecl_http 0.10.0-1.3.3)
Create HttpMessage from string

static HttpMessage|null
fromEnv(int $message_type, string $class_name = null)

(PECL pecl_http >= 1.5.0)
Create HttpMessage from environment

detach()

(PECL pecl_http >= 0.22.0)
Detach HttpMessage

void
prepend(HttpMessage $message, bool $top = null)

(PECL pecl_http >= 0.22.0)
Prepend message(s)

reverse()

(PECL pecl_http >= 0.23.0)
Reverse message chain

Details

__construct(string $message = null)

(PECL pecl_http >= 0.10.0)
HttpMessage constructor

Parameters

string $message

[optional]

a single or several consecutive HTTP messages

string getBody()

(PECL pecl_http >= 0.10.0)
Get message body

Return Value

string

the message body as string.

void setBody(string $body)

(PECL pecl_http >= 0.14.0)
Set message body

Parameters

string $body

the new body of the message

Return Value

void

string|null getHeader(string $header)

(PECL pecl_http >= 1.1.0)
Get header

Parameters

string $header

header name

Return Value

string|null

the header value on success or NULL if the header does not exist.

array getHeaders()

(PECL pecl_http >= 0.10.0)
Get message headers

Return Value

array

an associative array containing the messages HTTP headers.

void setHeaders(array $header)

(PECL pecl_http >= 0.10.0)
Set headers

Parameters

array $header

associative array containing the new HTTP headers, which will replace all previous HTTP headers of the message

Return Value

void

void addHeaders(array $headers, bool $append = null)

(PECL pecl_http >= 0.10.0)
Add headers

Parameters

array $headers

associative array containing the additional HTTP headers to add to the messages existing headers

bool $append

[optional]

if true, and a header with the same name of one to add exists already, this respective header will be converted to an array containing both header values, otherwise it will be overwritten with the new header value

Return Value

void

int getType()

(PECL pecl_http >= 0.10.0)
Get message type

Return Value

int

the HttpMessage::TYPE.

void setType(int $type)

(PECL pecl_http >= 0.10.0)
Set message type

Parameters

int $type

the HttpMessage::TYPE

Return Value

void

getInfo()

No description

setInfo($http_info)

No description

Parameters

$http_info

int|false getResponseCode()

(PECL pecl_http >= 0.10.0)
Get response code

Return Value

int|false

the HTTP response code if the message is of type HttpMessage::TYPE_RESPONSE, else FALSE.

bool setResponseCode(int $code)

(PECL pecl_http >= 0.10.0)
Set response code

Parameters

int $code

HTTP response code

Return Value

bool

TRUE on success, or FALSE if the message is not of type HttpMessage::TYPE_RESPONSE or the response code is out of range (100-510).

string getResponseStatus()

(PECL pecl_http >= 0.23.0)
Get response status

Return Value

string

the HTTP response status string if the message is of type HttpMessage::TYPE_RESPONSE, else FALSE.

bool setResponseStatus(string $status)

(PECL pecl_http >= 0.23.0)
Set response status

Parameters

string $status

the response status text

Return Value

bool

TRUE on success or FALSE if the message is not of type HttpMessage::TYPE_RESPONSE.

string|false getRequestMethod()

(PECL pecl_http >= 0.10.0)
Get request method

Return Value

string|false

the request method name on success, or FALSE if the message is not of type HttpMessage::TYPE_REQUEST.

bool setRequestMethod(string $method)

(PECL pecl_http >= 0.10.0)
Set request method

Parameters

string $method

the request method name

Return Value

bool

TRUE on success, or FALSE if the message is not of type HttpMessage::TYPE_REQUEST or an invalid request method was supplied.

string|false getRequestUrl()

(PECL pecl_http >= 0.21.0)
Get request URL

Return Value

string|false

the request URL as string on success, or FALSE if the message is not of type HttpMessage::TYPE_REQUEST.

bool setRequestUrl(string $url)

(PECL pecl_http >= 0.21.0)
Set request URL

Parameters

string $url

the request URL

Return Value

bool

TRUE on success, or FALSE if the message is not of type HttpMessage::TYPE_REQUEST or supplied URL was empty.

string getHttpVersion()

(PECL pecl_http >= 0.10.0)
Get HTTP version

Return Value

string

the HTTP protocol version as string.

bool setHttpVersion(string $version)

(PECL pecl_http >= 0.10.0)
Set HTTP version

Parameters

string $version

the HTTP protocol version

Return Value

bool

TRUE on success, or FALSE if supplied version is out of range (1.0/1.1).

string|false guessContentType(string $magic_file, int $magic_mode = null)

(PECL pecl_http >= 1.0.0)
Guess content type

Parameters

string $magic_file

the magic.mime database to use

int $magic_mode

[optional]

flags for libmagic

Return Value

string|false

the guessed content type on success or false on failure.

HttpMessage getParentMessage()

(PECL pecl_http >= 0.10.0)
Get parent message

Return Value

HttpMessage

the parent HttpMessage object.

bool send()

(PECL pecl_http >= 0.10.0)
Send message

Return Value

bool

true on success or false on failure.

string toString(bool $include_parent = null)

(PECL pecl_http >= 0.10.0)
Get string representation

Parameters

bool $include_parent

[optional]

specifies whether the returned string should also contain any parent messages

Return Value

string

the message as string.

HttpRequest|HttpResponse|null toMessageTypeObject()

(PECL pecl_http >= 0.22.0)
Create HTTP object regarding message type

Return Value

HttpRequest|HttpResponse|null

either an HttpRequest or HttpResponse object on success, or NULL on failure.

int count()

Count elements of an object

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

string|null serialize()

String representation of object.

Return Value

string|null

The string representation of the object or null

Exceptions

Exception

void unserialize($serialized)

No description

Parameters

$serialized

Return Value

void

void rewind()

Rewind the Iterator to the first element

Return Value

void

Any returned value is ignored.

bool valid()

Checks if current position is valid

Return Value

bool

The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.

mixed current()

Return the current element

Return Value

mixed

Can return any type.

mixed key()

Return the key of the current element

Return Value

mixed

TKey on success, or null on failure.

void next()

Move forward to next element

Return Value

void

Any returned value is ignored.

string __toString()

No description

Return Value

string

static HttpMessage|null factory(string $raw_message = null, string $class_name = null)

(PECL pecl_http >= 1.4.0)
Create HttpMessage from string

Parameters

string $raw_message

[optional]

a single or several consecutive HTTP messages

string $class_name

[optional]

a class extending HttpMessage

Return Value

HttpMessage|null

an HttpMessage object on success or NULL on failure.

static HttpMessage|null fromString(string $raw_message = null, string $class_name = null)

(PECL pecl_http 0.10.0-1.3.3)
Create HttpMessage from string

Parameters

string $raw_message

[optional]

a single or several consecutive HTTP messages

string $class_name

[optional]

a class extending HttpMessage

Return Value

HttpMessage|null

an HttpMessage object on success or NULL on failure.

static HttpMessage|null fromEnv(int $message_type, string $class_name = null)

(PECL pecl_http >= 1.5.0)
Create HttpMessage from environment

Parameters

int $message_type

The message type. See HttpMessage type constants.

string $class_name

[optional]

a class extending HttpMessage

Return Value

HttpMessage|null

an HttpMessage object on success or NULL on failure.

HttpMessage detach()

(PECL pecl_http >= 0.22.0)
Detach HttpMessage

Return Value

HttpMessage

detached HttpMessage object copy.

void prepend(HttpMessage $message, bool $top = null)

(PECL pecl_http >= 0.22.0)
Prepend message(s)

Parameters

HttpMessage $message

HttpMessage object to prepend

bool $top

[optional]

whether to prepend to the top most or right this message

Return Value

void

HttpMessage reverse()

(PECL pecl_http >= 0.23.0)
Reverse message chain

Return Value

HttpMessage

the most parent HttpMessage object.