X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_message_object.c;h=b02deadeec5cda526a1b6cb2ccfa76ee8bec7684;hb=f711df8e83b62938c05c2bf4ea544f095e80a2e9;hp=475daf13bb1dc300910ba64d3a2ecbd518e72061;hpb=389e280e0bba312ff5ca9981801cc842dad26ec2;p=m6w6%2Fext-http diff --git a/http_message_object.c b/http_message_object.c index 475daf1..b02dead 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -18,6 +18,7 @@ #ifdef ZEND_ENGINE_2 +#include "zend_interfaces.h" #include "ext/standard/url.h" #include "php_http_api.h" @@ -32,7 +33,6 @@ #include "php_http_request_object.h" #ifndef WONKY -# include "zend_interfaces.h" # ifdef HAVE_SPL /* SPL doesn't install its headers */ extern PHPAPI zend_class_entry *spl_ce_Countable; @@ -76,6 +76,11 @@ HTTP_BEGIN_ARGS(setResponseCode, 0, 1) HTTP_ARG_VAL(response_code, 0) HTTP_END_ARGS; +HTTP_EMPTY_ARGS(getResponseStatus, 0); +HTTP_BEGIN_ARGS(setResponseStatus, 0, 1) + HTTP_ARG_VAL(response_status, 0) +HTTP_END_ARGS; + HTTP_EMPTY_ARGS(getRequestMethod, 0); HTTP_BEGIN_ARGS(setRequestMethod, 0, 1) HTTP_ARG_VAL(request_method, 0) @@ -138,6 +143,8 @@ zend_function_entry http_message_object_fe[] = { HTTP_MESSAGE_ME(setType, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(getResponseCode, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(setResponseCode, ZEND_ACC_PUBLIC) + HTTP_MESSAGE_ME(getResponseStatus, ZEND_ACC_PUBLIC) + HTTP_MESSAGE_ME(setResponseStatus, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(getRequestMethod, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(setRequestMethod, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(getRequestUrl, ZEND_ACC_PUBLIC) @@ -253,6 +260,7 @@ static inline void _http_message_object_declare_default_properties(TSRMLS_D) DCL_PROP(PROTECTED, string, body, ""); DCL_PROP(PROTECTED, string, requestMethod, ""); DCL_PROP(PROTECTED, string, requestUrl, ""); + DCL_PROP(PROTECTED, string, responseStatus, ""); DCL_PROP(PROTECTED, long, responseCode, 0); DCL_PROP_N(PROTECTED, httpVersion); DCL_PROP_N(PROTECTED, headers); @@ -832,6 +840,50 @@ PHP_METHOD(HttpMessage, setResponseCode) } /* }}} */ +/* {{{ proto string HttpMessage::getResponseStatus() + * + * Get the Response Status of the message (i.e. the string following the response code). + * + * Returns the HTTP response status string if the message is of type + * HttpMessage::TYPE_RESPONSE, else FALSE. + */ +PHP_METHOD(HttpMessage, getResponseStatus) +{ + NO_ARGS; + + IF_RETVAL_USED { + getObject(http_message_object, obj); + HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE); + RETURN_STRING(obj->message->http.info.response.status, 1); + } +} +/* }}} */ + +/* {{{ proto bool HttpMessage::setResponseStatus(string status) + * + * Set the Response Status of the HTTP message (i.e. the string following the response code). + * + * Expects a string parameter containing the response status text. + * + * Returns TRUE on success or FALSE if the message is not of type + * HttpMessage::TYPE_RESPONSE. + */ +PHP_METHOD(HttpMessage, setResponseStatus) +{ + char *status; + int status_len; + getObject(http_message_object, obj); + + HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE); + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) { + RETURN_FALSE; + } + STR_SET(obj->message->http.info.response.status, estrdup(status)); + RETURN_TRUE; +} +/* }}} */ + /* {{{ proto string HttpMessage::getRequestMethod() * * Get the Request Method of the Message. @@ -1085,7 +1137,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) memset(&hurl, 0, sizeof(php_url)); hurl.host = host ? Z_STRVAL_P(host) : NULL; - http_build_url(purl, &hurl, NULL, &url, NULL); + http_build_url(HTTP_URL_REPLACE, purl, &hurl, NULL, &url, NULL); php_url_free(purl); add_assoc_string(array, "url", url, 0);