From 38ba1c26cfc9bc075be2173cadad4137a7879b32 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 14 Nov 2013 18:13:13 +0100 Subject: [PATCH] message --- http/Message.md | 34 ++++++++++++++++++ http/Message/Body/getBoundary.md | 13 +++++++ http/Message/Body/toCallback.md | 2 +- http/Message/__construct.md | 14 ++++++++ http/Message/__toString.md | 12 +++++++ http/Message/addBody.md | 13 +++++++ http/Message/addHeader.md | 30 ++++++++++++++++ http/Message/addHeaders.md | 54 +++++++++++++++++++++++++++++ http/Message/count.md | 11 ++++++ http/Message/current.md | 12 +++++++ http/Message/detach.md | 15 ++++++++ http/Message/getBody.md | 16 +++++++++ http/Message/getHeader.md | 38 +++++++++++++++++++++ http/Message/getHeaders.md | 12 +++++++ http/Message/getHttpVersion.md | 12 +++++++ http/Message/getInfo.md | 21 ++++++++++++ http/Message/getParentMessage.md | 32 +++++++++++++++++ http/Message/getRequestMethod.md | 17 +++++++++ http/Message/getRequestUrl.md | 17 +++++++++ http/Message/getResponseCode.md | 17 +++++++++ http/Message/getResponseStatus.md | 17 +++++++++ http/Message/getType.md | 12 +++++++ http/Message/isMultipart.md | 15 ++++++++ http/Message/key.md | 12 +++++++ http/Message/next.md | 9 +++++ http/Message/prepend.md | 20 +++++++++++ http/Message/reverse.md | 15 ++++++++ http/Message/rewind.md | 30 ++++++++++++++++ http/Message/serialize.md | 11 ++++++ http/Message/setBody.md | 13 +++++++ http/Message/setHeader.md | 15 ++++++++ http/Message/setHeaders.md | 43 +++++++++++++++++++++++ http/Message/setHttpVersion.md | 36 +++++++++++++++++++ http/Message/setInfo.md | 29 ++++++++++++++++ http/Message/setRequestMethod.md | 22 ++++++++++++ http/Message/setRequestUrl.md | 55 ++++++++++++++++++++++++++++++ http/Message/setResponseCode.md | 15 ++++++++ http/Message/setResponseStatus.md | 33 ++++++++++++++++++ http/Message/setType.md | 13 +++++++ http/Message/splitMultipartBody.md | 39 +++++++++++++++++++++ http/Message/toCallback.md | 16 +++++++++ http/Message/toStream.md | 16 +++++++++ http/Message/toString.md | 12 +++++++ http/Message/unserialize.md | 9 +++++ http/Message/valid.md | 12 +++++++ 45 files changed, 910 insertions(+), 1 deletion(-) create mode 100644 http/Message/Body/getBoundary.md create mode 100644 http/Message/__construct.md create mode 100644 http/Message/__toString.md create mode 100644 http/Message/addBody.md create mode 100644 http/Message/addHeader.md create mode 100644 http/Message/addHeaders.md create mode 100644 http/Message/count.md create mode 100644 http/Message/current.md create mode 100644 http/Message/detach.md create mode 100644 http/Message/getBody.md create mode 100644 http/Message/getHeader.md create mode 100644 http/Message/getHeaders.md create mode 100644 http/Message/getHttpVersion.md create mode 100644 http/Message/getInfo.md create mode 100644 http/Message/getParentMessage.md create mode 100644 http/Message/getRequestMethod.md create mode 100644 http/Message/getRequestUrl.md create mode 100644 http/Message/getResponseCode.md create mode 100644 http/Message/getResponseStatus.md create mode 100644 http/Message/getType.md create mode 100644 http/Message/isMultipart.md create mode 100644 http/Message/key.md create mode 100644 http/Message/next.md create mode 100644 http/Message/prepend.md create mode 100644 http/Message/reverse.md create mode 100644 http/Message/rewind.md create mode 100644 http/Message/serialize.md create mode 100644 http/Message/setBody.md create mode 100644 http/Message/setHeader.md create mode 100644 http/Message/setHeaders.md create mode 100644 http/Message/setHttpVersion.md create mode 100644 http/Message/setInfo.md create mode 100644 http/Message/setRequestMethod.md create mode 100644 http/Message/setRequestUrl.md create mode 100644 http/Message/setResponseCode.md create mode 100644 http/Message/setResponseStatus.md create mode 100644 http/Message/setType.md create mode 100644 http/Message/splitMultipartBody.md create mode 100644 http/Message/toCallback.md create mode 100644 http/Message/toStream.md create mode 100644 http/Message/toString.md create mode 100644 http/Message/unserialize.md create mode 100644 http/Message/valid.md diff --git a/http/Message.md b/http/Message.md index ce7603d..cdb4c30 100644 --- a/http/Message.md +++ b/http/Message.md @@ -1 +1,35 @@ # class http\Message extends http\Object implements Countable, Serializable, Iterator + +The message class builds the foundation for any request and response message. +See http\Client\Request and http\Client\Response, as well as http\Env\Request and http\Env\Response. + +## Constants: + +* TYPE_NONE + No specific type of message. +* TYPE_REQUEST + A request message. +* TYPE_RESPONSE + A response message. + +## Properties: + +* protected int $type = http\Message::TYPE_NONE + The message type. See http\Message::TYPE_* constants. +* protected http\Message\Body $body = NULL + The message's body. +* protected string $requestMethod = "" + The request method if the message is of type request. +* protected string $requestUrl = "" + The request url if the message is of type request. +* protected string $responseStatus = "" + The respose status phrase if the message is of type response. +* protected int $responseCode = 0 + The response code if the message is of type response. +* protected string $httpVersion = NULL + A custom HTTP protocol version. +* protected array $headers = NULL + Any message headers. +* protected http\Message $parentMessage + Any parent message. + diff --git a/http/Message/Body/getBoundary.md b/http/Message/Body/getBoundary.md new file mode 100644 index 0000000..20c830e --- /dev/null +++ b/http/Message/Body/getBoundary.md @@ -0,0 +1,13 @@ +# string http\Message\Body::getBoundary() + +Retrieve any boundary of tehe message body. +See http\Message::splitMultipartBody(). + +## Params: + +None. + +## Returns: + +* string, the message body boundary. +* NULL, if this message body has no boundary. diff --git a/http/Message/Body/toCallback.md b/http/Message/Body/toCallback.md index dab219a..117710e 100644 --- a/http/Message/Body/toCallback.md +++ b/http/Message/Body/toCallback.md @@ -5,7 +5,7 @@ Stream the message body through a callback. ## Params: * callable $callback - The callback of the form function(http\MessageBody $from, string $data). + The callback of the form function(http\Message\Body $from, string $data). * Optional int $offset = 0 Start to stream from this offset. * Optional int $maxlen = 0 diff --git a/http/Message/__construct.md b/http/Message/__construct.md new file mode 100644 index 0000000..61f7ef0 --- /dev/null +++ b/http/Message/__construct.md @@ -0,0 +1,14 @@ +# void http\Message::__construct([mixed $message = NULL[, bool $greedy = true]) + +Create a new HTTP message. + +## Params: + +* Optional mixed $message = NULL + Either a resource or a string, representing the HTTP message. +* Optional bool $greedy = true + Whether to read from a $message resource until EOF. + +## Throws: + +* http\Exception. diff --git a/http/Message/__toString.md b/http/Message/__toString.md new file mode 100644 index 0000000..116cebc --- /dev/null +++ b/http/Message/__toString.md @@ -0,0 +1,12 @@ +# string http\Message::__toString() + +Retrieve the message serialized to a string. +Alias of http\Message::toString(). + +## Params: + +None. + +## Returns: + +* string, the single serialized HTTP message. diff --git a/http/Message/addBody.md b/http/Message/addBody.md new file mode 100644 index 0000000..4ce36e7 --- /dev/null +++ b/http/Message/addBody.md @@ -0,0 +1,13 @@ +# http\Message http\Message::addBody(http\Message\Body $body) + +Append the data of $body to the message's body. +See http\Message::setBody() and http\Message\Body::append(). + +## Params: + +* http\Message\Body $body + The message body to add. + +## Returns: + +* http\Message, self. diff --git a/http/Message/addHeader.md b/http/Message/addHeader.md new file mode 100644 index 0000000..24a19a5 --- /dev/null +++ b/http/Message/addHeader.md @@ -0,0 +1,30 @@ +# http\Message http\Message::addHeader(string $name, mixed $value) + +Add an header, appending to already existing headers. +See http\Message::addHeaders() and http\Message::setHeader(). + +## Params: + +* string $name + The header name. +* mixed $value + The header value. + +## Returns: + +* http\Message, self. + +## Example: + + addHeader("X-Num", "123"); + $msg->addHeader("X-Num", "456"); + + echo $msg; + ?> + +Yields: + + X-Num: 123, 456 diff --git a/http/Message/addHeaders.md b/http/Message/addHeaders.md new file mode 100644 index 0000000..168803a --- /dev/null +++ b/http/Message/addHeaders.md @@ -0,0 +1,54 @@ +# http\Message http\Message::addHeaders(array $headers[, bool $append = false]) + +Add headers, optionally appending values, if header keys already exist. +See http\Message::addHeader() and http\Message::setHeaders(). + +## Params: + +* array $headers + The HTTP headers to add. +* Optional bool $append = false + Whether to append values for existing headers. + +## Returns: + +* http\Message, self. + +## Example: + + addHeaders(["Cache-Control" => "public"]); + var_dump($msg->getHeaders()); + + $msg->addHeaders(["Cache-Control" => "private"]); + var_dump($msg->getHeaders()); + + $msg->addHeaders(["Cache-Control" => "must-revalidate"], true); + var_dump($msg->getHeaders()); + + echo $msg; + ?> + +Yields: + + array(1) { + ["Cache-Control"]=> + string(6) "public" + } + array(1) { + ["Cache-Control"]=> + string(7) "private" + } + array(1) { + ["Cache-Control"]=> + array(2) { + [0]=> + string(7) "private" + [1]=> + string(15) "must-revalidate" + } + } + Cache-Control: private, must-revalidate + diff --git a/http/Message/count.md b/http/Message/count.md new file mode 100644 index 0000000..fe0e677 --- /dev/null +++ b/http/Message/count.md @@ -0,0 +1,11 @@ +# int http\Message::count() + +Implements Countable. + +## Params: + +None. + +## Returns: + +* int, thre count of messages in the chain above the current message. diff --git a/http/Message/current.md b/http/Message/current.md new file mode 100644 index 0000000..fa1eaa2 --- /dev/null +++ b/http/Message/current.md @@ -0,0 +1,12 @@ +# http\Message http\Message::current() + +Implements iterator. +See http\Message::valid() and http\Message::rewind(). + +## Params: + +None. + +## Returns: + +* http\Message, the current message in the iterated message chain. diff --git a/http/Message/detach.md b/http/Message/detach.md new file mode 100644 index 0000000..fa12d44 --- /dev/null +++ b/http/Message/detach.md @@ -0,0 +1,15 @@ +# http\Message http\Message::detach() + +Detach a clone of this message from any message chain. + +## Params: + +None. + +## Returns: + +* http\Message, clone. + +## Throws: + +* http\Exception. diff --git a/http/Message/getBody.md b/http/Message/getBody.md new file mode 100644 index 0000000..013f22a --- /dev/null +++ b/http/Message/getBody.md @@ -0,0 +1,16 @@ +# http\Message\Body http\Message::getBody() + +Retrieve the message's body. +See http\Message::setBody(). + +## Params: + +None. + +## Returns: + +* http\Message\Body, the message body. + +## Throws: + +* http\Exception. diff --git a/http/Message/getHeader.md b/http/Message/getHeader.md new file mode 100644 index 0000000..08efe96 --- /dev/null +++ b/http/Message/getHeader.md @@ -0,0 +1,38 @@ +# mixed http\Message::getHeader(string $header[, string $into_class = NULL]) + +Retrieve a single header, optionally hydrated into a http\Header extending class. + +## Params: + +* string $header + The header's name. +* Optional string $into_class = NULL + The name of a class extending http\Header. + +## Returns: + +* mixed, the header value if $into_class is NULL. +* http\Header, descendant. + +## Warnings: + +* E_INVALID_PARAM, if $into_class is not a descendant of http\Header. + +## Example: + + getHeader("foo", "hdr"); + ?> + +Yields: + + string(3) "foo" + string(3) "bar" diff --git a/http/Message/getHeaders.md b/http/Message/getHeaders.md new file mode 100644 index 0000000..7029508 --- /dev/null +++ b/http/Message/getHeaders.md @@ -0,0 +1,12 @@ +# array http\Message::getHeaders() + +Retrieve all message headers. +See http\Message::setHeaders() and http\Message::getHeader(). + +## Params: + +None. + +## Returns: + +* array, the message's headers. diff --git a/http/Message/getHttpVersion.md b/http/Message/getHttpVersion.md new file mode 100644 index 0000000..29d65d7 --- /dev/null +++ b/http/Message/getHttpVersion.md @@ -0,0 +1,12 @@ +# string http\Message::getHttpVersion() + +Retreive the HTTP protocol version of the message. +See http\Message::setHttpVersion(). + +## Params: + +None. + +## Returns: + +* string, the HTTP protocol version, e.g. "1.0"; defaults to "1.1". diff --git a/http/Message/getInfo.md b/http/Message/getInfo.md new file mode 100644 index 0000000..ec9e2bc --- /dev/null +++ b/http/Message/getInfo.md @@ -0,0 +1,21 @@ +# string http\Message::getInfo() + +Retrieve the first line of a request or response message. +See http\Message::setInfo and also: + +* http\Message::getType() +* http\Message::getHttpVersion() +* http\Message::getResponseCode() +* http\Message::getResponseStatus() +* http\Message::getRequestMethod() +* http\Message::getRequestUrl() + +## Params: + +None. + +## Return: + +* string, the HTTP message information. +* NULL, if the message is neither of type request nor response. + diff --git a/http/Message/getParentMessage.md b/http/Message/getParentMessage.md new file mode 100644 index 0000000..ace45d5 --- /dev/null +++ b/http/Message/getParentMessage.md @@ -0,0 +1,32 @@ +# http\Message http\Message::getParentMessage() + +Retrieve any parent message. +See http\Message::reverse(). + +## Params: + +None. + +## Returns: + +* http/Message, the parent message. + +## Throws: + +* http\Exception. + + +## Example: + + getParentMessage()->toString()); + ?> + +Yields: + + string(16) "GET / HTTP/1.0 + " diff --git a/http/Message/getRequestMethod.md b/http/Message/getRequestMethod.md new file mode 100644 index 0000000..14c73b6 --- /dev/null +++ b/http/Message/getRequestMethod.md @@ -0,0 +1,17 @@ +# string http\Message::getRequestMethod() + +Retrieve the request method of the message. +See http\Message::setRequestMethod() and http\Message::getRequestUrl(). + +## Params: + +None. + +## Returns: + +* string, the request method. +* false, if the message was not of type request. + +## Notices: + +* E_MESSAGE_TYPE, if the message is not of type request. diff --git a/http/Message/getRequestUrl.md b/http/Message/getRequestUrl.md new file mode 100644 index 0000000..0c0069c --- /dev/null +++ b/http/Message/getRequestUrl.md @@ -0,0 +1,17 @@ +# string http\Message::getRequestUrl() + +Retrieve the request URL of the message. +See http\Message::setRequestUrl(). + +## Params: + +None. + +## Returns: + +* string, the request URL; usually the path and the querystring. +* false, if the message was not of type request. + +## Notices: + +* E_MESSAGE_TYPE, if the message is not of type request. diff --git a/http/Message/getResponseCode.md b/http/Message/getResponseCode.md new file mode 100644 index 0000000..8303203 --- /dev/null +++ b/http/Message/getResponseCode.md @@ -0,0 +1,17 @@ +# int http\Message::getResponseCode() + +Retrieve the response code of the message. +See http\Message::setResponseCode() and http\Massage::getResponseStatus(). + +## Params: + +None. + +## Returns: + +* int, the response status code. +* false, if the message is not of type response. + +## Notices: + +* E_MESSAGE_TYPE, if the message is not of type response. diff --git a/http/Message/getResponseStatus.md b/http/Message/getResponseStatus.md new file mode 100644 index 0000000..d90cee1 --- /dev/null +++ b/http/Message/getResponseStatus.md @@ -0,0 +1,17 @@ +# string http\Message::getResponseStatus() + +Retrieve the response status of the message. +See http\Message::setResponseStatus() and http\Message::getResponseCode(). + +## Params: + +None. + +## Returns: + +* string, the response status phrase. +* false, if the message is not of type response. + +## Notices: + +* E_MESSAGE_TYPE, if the message is not of type response. diff --git a/http/Message/getType.md b/http/Message/getType.md new file mode 100644 index 0000000..b681e7e --- /dev/null +++ b/http/Message/getType.md @@ -0,0 +1,12 @@ +# int http\Message::getType() + +Retrieve the type of the message. +See http\Message::setType() and http\Message::getInfo(). + +## Params: + +None. + +## Returns: + +* int, the message type. See http\Message::TYPE_* constants. diff --git a/http/Message/isMultipart.md b/http/Message/isMultipart.md new file mode 100644 index 0000000..e61ae90 --- /dev/null +++ b/http/Message/isMultipart.md @@ -0,0 +1,15 @@ +# bool http\Message::isMultipart([string &$boundary = NULL]) + +Check whether this message is a multipart message based on it's content type. +If the message is a multipart message and a reference $boundary is given, the boundary string of the multipart message will be stored in $boundary. + +See http\Message::splitMultipartBody(). + +## Params: + +* Optional reference string &$boundary = NULL + A reference where the boundary string will be stored. + +## Returns: + +* bool, whether this is a message with a multipart "Content-Type". diff --git a/http/Message/key.md b/http/Message/key.md new file mode 100644 index 0000000..89d239d --- /dev/null +++ b/http/Message/key.md @@ -0,0 +1,12 @@ +# int http\Message::key() + +Implements Iterator. +See http\Message::current() and http\Message::rewind(). + +## Params: + +None. + +## Returns: + +* int, a non-sequential integer key. diff --git a/http/Message/next.md b/http/Message/next.md new file mode 100644 index 0000000..1e4e26e --- /dev/null +++ b/http/Message/next.md @@ -0,0 +1,9 @@ +# void http\Message::next() + +Implements Iterator. +See http\Message::valid() and http\Message::rewind(). + +## Params: + +None. + diff --git a/http/Message/prepend.md b/http/Message/prepend.md new file mode 100644 index 0000000..e010901 --- /dev/null +++ b/http/Message/prepend.md @@ -0,0 +1,20 @@ +# http\Message http\Message::prepend(http\Message $message[, bool $top = true]) + +Prepend message(s) $message to this message, or the top most message of this message chain. + +> **Note:** The message chains must not overlap. + +## Params: + +* http\Message $message + The message (chain) to prepend as parent messages. +* Optional bool $top = true + Whether to prepend to the top-most parent message. + +## Returns: + +* http\Message, self. + +## Throws: + +* http\Exception. diff --git a/http/Message/reverse.md b/http/Message/reverse.md new file mode 100644 index 0000000..12030e9 --- /dev/null +++ b/http/Message/reverse.md @@ -0,0 +1,15 @@ +# http\Message http\Messae::reverse() + +Reverse the message chain and return the former top-most message. + +> **Note:** Message chains are ordered in reverse-parsed order by default, i.e. the last parsed message is the message you'll receive from any call parsing HTTP messages. +> +> This call re-orders the messages of the chain and returns the message that was parsed first with any later parsed messages re-parentized. + +## Params: + +None. + +## Returns: + +* http\Message, the other end of the message chain. diff --git a/http/Message/rewind.md b/http/Message/rewind.md new file mode 100644 index 0000000..5362b60 --- /dev/null +++ b/http/Message/rewind.md @@ -0,0 +1,30 @@ +# void http\Message::rewind() + +Implements Iterator. + +## Params: + +None. + +## Example: + + $msg) { + printf("Key %d is a %8s: %s\n", + $key, ["message", "request", "response"][$msg->getType()], + $msg->getInfo() + ); + } + ?> + +Yields: + + Key 2 is a response: HTTP/1.0 426 + Key 8 is a request: GET / HTTP/1.0 + Key 6 is a response: HTTP/1.1 200 + Key 4 is a request: GET / HTTP/1.1 diff --git a/http/Message/serialize.md b/http/Message/serialize.md new file mode 100644 index 0000000..ce800c0 --- /dev/null +++ b/http/Message/serialize.md @@ -0,0 +1,11 @@ +# string http\Message::serialize() + +Implements Serializable. + +## Params: + +None. + +## Returns: + +* string, the serialized HTTP message. diff --git a/http/Message/setBody.md b/http/Message/setBody.md new file mode 100644 index 0000000..9cd55f8 --- /dev/null +++ b/http/Message/setBody.md @@ -0,0 +1,13 @@ +# http\Message http\Message::setBody(http\Message\Body $body) + +Set the message's body. +See http\Message::getBody() and http\Message::addBody(). + +## Params: + +* http\Message\Body $body + The new message body. + +## Returns: + +* http\Message, self. diff --git a/http/Message/setHeader.md b/http/Message/setHeader.md new file mode 100644 index 0000000..e5fa062 --- /dev/null +++ b/http/Message/setHeader.md @@ -0,0 +1,15 @@ +# http\Message http\Message::setHeader(string $header[, mixed $value = NULL]) + +Set a single header. +See http\Message::getHeader() and http\Message::addHeader(). + +## Params: + +* string $header + The header's name. +* Optional mixed $value = NULL + The header's value. Removes the header if NULL. + +## Returns: + +* http\Message, self. diff --git a/http/Message/setHeaders.md b/http/Message/setHeaders.md new file mode 100644 index 0000000..875d49e --- /dev/null +++ b/http/Message/setHeaders.md @@ -0,0 +1,43 @@ +# http\Message http\Message::setHeaders(array $headers = NULL) + +Set the message headers. +See http\Message::getHeaders() and http\Message::addHeaders(). + +## Params: + +* array $headers = NULL + The message's headers. + +## Returns: + +* http\Message, null. + +## Example: + + setHeaders([ + "Content-Type" => "text/plain", + "Content-Encoding" => "gzip", + "Content-Location" => "/foo/bar" + ]); + var_dump($msg->getHeaders()); + + $msg->setHeaders(null); + var_dump($msg->getHeaders()); + ?> + +Yields: + + array(3) { + ["Content-Type"]=> + string(10) "text/plain" + ["Content-Encoding"]=> + string(4) "gzip" + ["Content-Location"]=> + string(8) "/foo/bar" + } + array(0) { + } + diff --git a/http/Message/setHttpVersion.md b/http/Message/setHttpVersion.md new file mode 100644 index 0000000..ee9ab0a --- /dev/null +++ b/http/Message/setHttpVersion.md @@ -0,0 +1,36 @@ +# http\Message http\Message::setHttpVersion(string $http_version) + +Set the HTTP protocol version of the message. +See http\Message::getHttpVersion(). + +## Params: + +* string $http_version + The protocol version, e.g. "1.1", optionally prefixed by "HTTP/". + +## Returns: + +* http\Message, self. + +## Notices: + +* E_MALFORMED_HEADERS, if the version separator is non-standard. + +## Warnings: + +* E_MALFORMED_HEADERS, if the version could not be parsed. + +## Example: + + getHttpVersion()); + $message->setHttpVersion("HTTP/1_0"); + var_dump($message->getHttpVersion()); + ?> + +Yields: + + string(3) "1.1" + Notice: Non-standard version separator '_' in HTTP protocol version 'HTTP/1_0' + string(3) "1.0" diff --git a/http/Message/setInfo.md b/http/Message/setInfo.md new file mode 100644 index 0000000..36e63fa --- /dev/null +++ b/http/Message/setInfo.md @@ -0,0 +1,29 @@ +# http\Message http\Message::setInfo(string $http_info) + +Set the complete message info, i.e. type and response resp. request information, at once. +See http\Message::getInfo(). + +## Params: + +* string $http_info + The message info (first line of an HTTP message). + +## Returns: + +* http\Message, self. + +## Warnings: + +* E_MALFORMED_HEADERS, if the message information could not be parsed. + +## Format of the message info: + +The message info looks similar to the following line for a response, see also http\Message::setResponseCode() and http\Message::setResponseStatus(): + + HTTP/1.1 200 Ok + +The message info looks similar to the following line for a request, see also http\Message::setRequestMethod() and http\Message::setRequestUrl(): + + GET / HTTP/1.1 + +See http\Message::setHttpVersion(). diff --git a/http/Message/setRequestMethod.md b/http/Message/setRequestMethod.md new file mode 100644 index 0000000..a15e9c1 --- /dev/null +++ b/http/Message/setRequestMethod.md @@ -0,0 +1,22 @@ +# http\Message http\Message::setRequestMethod(string $method) + +Set the request method of the message. +See http\Message::getRequestMethod() and http\Message::setRequestUrl(). + +## Params: + +* string $method + The request method. + +## Returns: + +* http\Message, self. +* false, if the message was not of type request. + +## Notices: + +* E_MESSAGE_TYPE, if the message is not of type request. + +## Warnings: + +* E_INVALID_PARAM, if the method is of zero length. diff --git a/http/Message/setRequestUrl.md b/http/Message/setRequestUrl.md new file mode 100644 index 0000000..9c6663d --- /dev/null +++ b/http/Message/setRequestUrl.md @@ -0,0 +1,55 @@ +# http\Message http\Message::setRequestUrl(string $url) + +Set the request URL of the message. +See http\Message::getRequestUrl() and http\Message::setRequestMethod(). + +## Params: + +* string $url + The request URL. + +## Returns: + +* http\Message, self. +* false, if the message was not of type request. + +## Notices: + +* E_MESSAGE_TYPE, if the message is not of type request. + +## Warnings: + +* E_INVALID_PARAM, if the url is of zero length. + +## Example: + +> **Note:** The request URL in a request message usually only consists of the path and the querystring. + + setType(http\Message::TYPE_REQUEST); + $m->setRequestMethod("GET"); + $m->setRequestUrl("http://foo.bar/baz?q"); + echo $m; + ?> + +Yields: + + GET http://foo.bar/baz?q HTTP/1.1 + +Maybe you did not really expect this, so let's try this: + + setType(http\Message::TYPE_REQUEST); + $m->setRequestMethod("GET"); + $m->setRequestUrl($u->path ."?". $u->query); + $m->setHeader("Host", $u->host); + echo $m; + ?> + +Yields: + + GET /baz?q HTTP/1.1 + Host: foo.bar diff --git a/http/Message/setResponseCode.md b/http/Message/setResponseCode.md new file mode 100644 index 0000000..58c8d82 --- /dev/null +++ b/http/Message/setResponseCode.md @@ -0,0 +1,15 @@ +# http\Message http\Message::setResponseCode(int $response_code) + +Set the response status code. +See http\Message::getResponseCode() and http\Message::setResponseStatus(). + +## Params: + +* int $response_code + The response code. + +## Returns: + +* http\Message, self. +* false, if the message is not of type response. + diff --git a/http/Message/setResponseStatus.md b/http/Message/setResponseStatus.md new file mode 100644 index 0000000..b1ba286 --- /dev/null +++ b/http/Message/setResponseStatus.md @@ -0,0 +1,33 @@ +# http\Message http\Message::setResponseStatus(string $response_status) + +Set the response status phrase. +See http\Message::getResponseStatus() and http\Message::setResponseCode(). + +## Params: + +* string $response_status + The status phrase. + +## Returns: + +* http\Message, self. +* false, if the message is not of type response. + +## Notice: + +* E_MESSAGE_TYPE, if the message is not of type response. + + +## Example: + + setType(http\Message::TYPE_RESPONSE); + $message->setResponseCode(200); + $message->setResponseStatus("Ok"); + echo $message; + ?> + +Yields: + + HTTP/1.1 200 Ok diff --git a/http/Message/setType.md b/http/Message/setType.md new file mode 100644 index 0000000..bc51350 --- /dev/null +++ b/http/Message/setType.md @@ -0,0 +1,13 @@ +# http\Message http\Message::setType(int $type) + +Set the message type and reset the message info. +See http\Message::getType() and http\Message::setInfo(). + +## Params: + +* int $type + The desired message type. See the http\Message::TYPE_* constants. + +## Returns: + +* http\Message, self. diff --git a/http/Message/splitMultipartBody.md b/http/Message/splitMultipartBody.md new file mode 100644 index 0000000..10f2ac6 --- /dev/null +++ b/http/Message/splitMultipartBody.md @@ -0,0 +1,39 @@ +# http\Message http\Message::splitMultipartBody() + +Splits the body of a multipart message. +See http\Message::isMultipart() and http\Message\Body::addPart(). + +## Params: + +None. + +## Returns: + +* http\Message, a message chain of all messages of the multipart body. + +## Example: + + addPart(new http\Message("Content-type: text/plain\n\nHello ")); + $body->addPart(new http\Message("Content-type: text/plain\n\nWorld!")); + + $msg = new http\Message; + $msg->setHeader("Content-Type", + "multipart/mixed; boundary=" . $body->getBoundary()); + $msg->setBody($body); + var_dump($msg->isMultipart($bnd), $bnd); + + $parts = $msg->splitMultipartBody(); + var_dump(count($parts)); + foreach ($parts->reverse() as $part) { + echo $part->getBody(); + } + ?> + +Yields: + + bool(true) + string(17) "16658735.3fe37486" + int(2) + Hello World! diff --git a/http/Message/toCallback.md b/http/Message/toCallback.md new file mode 100644 index 0000000..fc48ffe --- /dev/null +++ b/http/Message/toCallback.md @@ -0,0 +1,16 @@ +# http\Message http\Message::toCallback(callable $callback[, int $offset = 0[, int $maxlen = 0]]) + +Stream the message through a callback. + +## Params: + +* callable $callback + The callback of the form function(http\Message $from, string $data). +* Optional int $offset = 0 + Start to stream from this offset. +* Optional int $maxlen = 0 + Stream at most $maxlen bytes, or all if $maxlen is less than 1. + +## Returns: + +* http\Message, self. diff --git a/http/Message/toStream.md b/http/Message/toStream.md new file mode 100644 index 0000000..31ff77c --- /dev/null +++ b/http/Message/toStream.md @@ -0,0 +1,16 @@ +# http\Message http\Message::toStream(resource $stream[, int $offset = 0[, int $maxlen = 0]]) + +Stream the message into stream $stream, starting from $offset, streaming $maxlen at most. + +## Params: + +* resource $stream + The resource to write to. +* Optional int $offset = 0 + The starting offset. +* Optional int $maxlen = 0 + The maximum amount of data to stream. All content if less than 1. + +## Returns: + +* http\Message, self. diff --git a/http/Message/toString.md b/http/Message/toString.md new file mode 100644 index 0000000..245a155 --- /dev/null +++ b/http/Message/toString.md @@ -0,0 +1,12 @@ +# string http\Message::toString([bool $include_parent = false]) + +Retrieve the message serialized to a string. + +## Params: + +* Optional bool $include_parent = false + Whether to include all parent messages. + +## Returns: + +* string, the HTTP message chain serialized to a string. diff --git a/http/Message/unserialize.md b/http/Message/unserialize.md new file mode 100644 index 0000000..1648ced --- /dev/null +++ b/http/Message/unserialize.md @@ -0,0 +1,9 @@ +# void http\Message::unserualize(string $data) + +Implements Serializable. + +## Params: + +* string $data + The serialized message. + diff --git a/http/Message/valid.md b/http/Message/valid.md new file mode 100644 index 0000000..2487c82 --- /dev/null +++ b/http/Message/valid.md @@ -0,0 +1,12 @@ +# bool http\Message::valid() + +Implements Iterator. +See http\Message::current() and http\Message::rewind(). + +## Params: + +None. + +## Returns: + +* bool, whether http\Message::current() would not return NULL. -- 2.30.2