From 73508c8e9957ba07de65e41342f74fd49a8ce13a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 7 Jul 2006 11:49:30 +0000 Subject: [PATCH] - add HttpMessage::get(string $name) --- docs/functions.html | 6 +++++- http_message_object.c | 30 ++++++++++++++++++++++++++++++ package2.xml | 3 ++- php_http_message_object.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/functions.html b/docs/functions.html index c3d2aad..f78ada3 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -513,6 +513,9 @@ HTTP messages. Accepts an optional string parameter specifying the class to use

Set the body of the HttpMessage.
NOTE: Don't forget to update any headers accordingly.

Expects a string parameter containing the new body of the message.

+

string HttpMessage::getHeader(string header)

+

Get message header.

+

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

array HttpMessage::getHeaders()

Get Message Headers.

Returns an associative array containing the messages HTTP headers.

@@ -1287,6 +1290,7 @@ http.cache_log is set.

  • HttpMessage::fromString()
  • HttpMessage::getBody()
  • HttpMessage::setBody()
  • +
  • HttpMessage::getHeader()
  • HttpMessage::getHeaders()
  • HttpMessage::setHeaders()
  • HttpMessage::addHeaders()
  • @@ -1449,7 +1453,7 @@ http.cache_log is set.

    -

    Generated at: Thu, 06 Jul 2006 20:17:57 +0200

    +

    Generated at: Fri, 07 Jul 2006 13:48:43 +0200

    diff --git a/http_message_object.c b/http_message_object.c index a1b3141..eb35995 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -55,6 +55,10 @@ HTTP_BEGIN_ARGS(setBody, 1) HTTP_ARG_VAL(body, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(getHeader, 1) + HTTP_ARG_VAL(header, 0) +HTTP_END_ARGS; + HTTP_EMPTY_ARGS(getHeaders); HTTP_BEGIN_ARGS(setHeaders, 1) HTTP_ARG_VAL(headers, 0) @@ -140,6 +144,7 @@ zend_function_entry http_message_object_fe[] = { HTTP_MESSAGE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) HTTP_MESSAGE_ME(getBody, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(setBody, ZEND_ACC_PUBLIC) + HTTP_MESSAGE_ME(getHeader, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(getHeaders, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(setHeaders, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(addHeaders, ZEND_ACC_PUBLIC) @@ -783,6 +788,31 @@ PHP_METHOD(HttpMessage, setBody) } /* }}} */ +/* {{{ proto string HttpMessage::getHeader(string header) + * + * Get message header. + * + * Returns the header value on success or NULL if the header does not exist. + */ +PHP_METHOD(HttpMessage, getHeader) +{ + zval *header; + char *orig_header, *nice_header; + int header_len; + getObject(http_message_object, obj); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &orig_header, &header_len)) { + RETURN_FALSE; + } + + nice_header = pretty_key(estrndup(orig_header, header_len), header_len, 1, 1); + if ((header = http_message_header_ex(obj->message, nice_header, header_len + 1))) { + RETVAL_ZVAL(header, 1, 0); + } + efree(nice_header); +} +/* }}} */ + /* {{{ proto array HttpMessage::getHeaders() * * Get Message Headers. diff --git a/package2.xml b/package2.xml index 275c6db..646928f 100644 --- a/package2.xml +++ b/package2.xml @@ -40,7 +40,8 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised diff --git a/php_http_message_object.h b/php_http_message_object.h index 38030ad..7f47167 100644 --- a/php_http_message_object.h +++ b/php_http_message_object.h @@ -80,6 +80,7 @@ extern void _http_message_object_free(zend_object *object TSRMLS_DC); PHP_METHOD(HttpMessage, __construct); PHP_METHOD(HttpMessage, getBody); PHP_METHOD(HttpMessage, setBody); +PHP_METHOD(HttpMessage, getHeader); PHP_METHOD(HttpMessage, getHeaders); PHP_METHOD(HttpMessage, setHeaders); PHP_METHOD(HttpMessage, addHeaders); -- 2.30.2