- add HTTP_URL_STRIP_ALL constant
[m6w6/ext-http] / http_request_object.c
index 87bfb65ce5a1187126f7c706d7bd945cac90f5c5..1c0f39a6b106774320dcb785e58b851a9b1e71c9 100644 (file)
@@ -190,6 +190,13 @@ HTTP_BEGIN_ARGS(postFields, 2)
        HTTP_ARG_VAL(info, 1)
 HTTP_END_ARGS;
 
+HTTP_BEGIN_ARGS(putData, 2)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(data, 0)
+       HTTP_ARG_VAL(options, 0)
+       HTTP_ARG_VAL(info, 1)
+HTTP_END_ARGS;
+
 HTTP_BEGIN_ARGS(putFile, 2)
        HTTP_ARG_VAL(url, 0)
        HTTP_ARG_VAL(file, 0)
@@ -220,8 +227,10 @@ HTTP_BEGIN_ARGS(methodExists, 1)
        HTTP_ARG_VAL(method, 0)
 HTTP_END_ARGS;
 
-#define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C)
-static inline void _http_request_object_declare_default_properties(TSRMLS_D);
+HTTP_BEGIN_ARGS(encodeBody, 2)
+       HTTP_ARG_VAL(fields, 0)
+       HTTP_ARG_VAL(files, 0)
+HTTP_END_ARGS;
 
 #define OBJ_PROP_CE http_request_object_ce
 zend_class_entry *http_request_object_ce;
@@ -294,6 +303,7 @@ zend_function_entry http_request_object_fe[] = {
        HTTP_REQUEST_ALIAS(head, http_head)
        HTTP_REQUEST_ALIAS(postData, http_post_data)
        HTTP_REQUEST_ALIAS(postFields, http_post_fields)
+       HTTP_REQUEST_ALIAS(putData, http_put_data)
        HTTP_REQUEST_ALIAS(putFile, http_put_file)
        HTTP_REQUEST_ALIAS(putStream, http_put_stream)
 
@@ -301,6 +311,8 @@ zend_function_entry http_request_object_fe[] = {
        HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister)
        HTTP_REQUEST_ALIAS(methodName, http_request_method_name)
        HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists)
+       
+       HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode)
 
        EMPTY_FUNCTION_ENTRY
 };
@@ -310,60 +322,6 @@ PHP_MINIT_FUNCTION(http_request_object)
 {
        HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0);
        http_request_object_handlers.clone_obj = _http_request_object_clone_obj;
-       return SUCCESS;
-}
-
-zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
-{
-       return http_request_object_new_ex(ce, NULL, NULL);
-}
-
-zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC)
-{
-       zend_object_value ov;
-       http_request_object *o;
-
-       o = ecalloc(1, sizeof(http_request_object));
-       o->zo.ce = ce;
-       o->request = http_request_init_ex(NULL, ch, 0, NULL);
-       
-       if (ptr) {
-               *ptr = o;
-       }
-
-       ALLOC_HASHTABLE(OBJ_PROP(o));
-       zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0);
-       zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
-
-       ov.handle = putObject(http_request_object, o);
-       ov.handlers = &http_request_object_handlers;
-
-       return ov;
-}
-
-zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
-{
-       zend_object *old_zo;
-       zend_object_value new_ov;
-       http_request_object *new_obj;
-       getObject(http_request_object, old_obj);
-       
-       old_zo = zend_objects_get_address(this_ptr TSRMLS_CC);
-       new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj);
-       if (old_obj->request->ch) {
-               http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request);
-       }
-       
-       zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
-       phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
-       phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
-       
-       return new_ov;
-}
-
-static inline void _http_request_object_declare_default_properties(TSRMLS_D)
-{
-       zend_class_entry *ce = http_request_object_ce;
 
        DCL_PROP_N(PRIVATE, options);
        DCL_PROP_N(PRIVATE, postFields);
@@ -386,7 +344,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
 #ifndef WONKY
        /*
         * Request Method Constants
-        */
+       */
        /* HTTP/1.1 */
        DCL_CONST(long, "METH_GET", HTTP_GET);
        DCL_CONST(long, "METH_HEAD", HTTP_HEAD);
@@ -419,19 +377,80 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
        /* WebDAV Access Control - RFC 3744 */
        DCL_CONST(long, "METH_ACL", HTTP_ACL);
 
-       /* cURL HTTP protocol versions */
+       /*
+       * HTTP Protocol Version Constants
+       */
        DCL_CONST(long, "VERSION_1_0", CURL_HTTP_VERSION_1_0);
        DCL_CONST(long, "VERSION_1_1", CURL_HTTP_VERSION_1_1);
        DCL_CONST(long, "VERSION_NONE", CURL_HTTP_VERSION_NONE);
 
        /*
-        * Auth Constants
-        */
+       * Auth Constants
+       */
        DCL_CONST(long, "AUTH_BASIC", CURLAUTH_BASIC);
        DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST);
        DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM);
        DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY);
+       
+       /*
+       * Proxy Type Constants
+       */
+#      if HTTP_CURL_VERSION(7,15,2)
+       DCL_CONST(long, "PROXY_SOCKS4", CURLPROXY_SOCKS4);
+#      endif
+       DCL_CONST(long, "PROXY_SOCKS5", CURLPROXY_SOCKS5);
+       DCL_CONST(long, "PROXY_HTTP", CURLPROXY_HTTP);
 #endif /* WONKY */
+       
+       return SUCCESS;
+}
+
+zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
+{
+       return http_request_object_new_ex(ce, NULL, NULL);
+}
+
+zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC)
+{
+       zend_object_value ov;
+       http_request_object *o;
+
+       o = ecalloc(1, sizeof(http_request_object));
+       o->zo.ce = ce;
+       o->request = http_request_init_ex(NULL, ch, 0, NULL);
+       
+       if (ptr) {
+               *ptr = o;
+       }
+
+       ALLOC_HASHTABLE(OBJ_PROP(o));
+       zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
+       zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+
+       ov.handle = putObject(http_request_object, o);
+       ov.handlers = &http_request_object_handlers;
+
+       return ov;
+}
+
+zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
+{
+       zend_object *old_zo;
+       zend_object_value new_ov;
+       http_request_object *new_obj;
+       getObject(http_request_object, old_obj);
+       
+       old_zo = zend_objects_get_address(this_ptr TSRMLS_CC);
+       new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj);
+       if (old_obj->request->ch) {
+               http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request);
+       }
+       
+       zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+       phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
+       phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
+       
+       return new_ov;
 }
 
 void _http_request_object_free(zend_object *object TSRMLS_DC)
@@ -453,15 +472,32 @@ static inline void _http_request_object_check_request_content_type(zval *this_pt
                                
        if (Z_STRLEN_P(ctype)) {
                zval **headers, *opts = GET_PROP(options);
-                                       
+               
                if (    (Z_TYPE_P(opts) == IS_ARRAY) &&
-                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && 
+                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void *) &headers)) && 
                                (Z_TYPE_PP(headers) == IS_ARRAY)) {
                        zval **ct_header;
-                                               
+                       
                        /* only override if not already set */
-                       if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header))) {
+                       if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void *) &ct_header))) {
                                add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+                       } else
+                       /* or not a string, zero length string or a string of spaces */
+                       if ((Z_TYPE_PP(ct_header) != IS_STRING) || !Z_STRLEN_PP(ct_header)) {
+                               add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+                       } else {
+                               int i, only_space = 1;
+                               
+                               /* check for spaces only */
+                               for (i = 0; i < Z_STRLEN_PP(ct_header); ++i) {
+                                       if (!isspace(Z_STRVAL_PP(ct_header)[i])) {
+                                               only_space = 0;
+                                               break;
+                                       }
+                               }
+                               if (only_space) {
+                                       add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+                               }
                        }
                } else {
                        zval *headers;
@@ -559,7 +595,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        zval **entry, *pcb;
                        
                        if (    (Z_TYPE_P(options) != IS_ARRAY)
-                               ||      (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void **) &entry)
+                               ||      (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void *) &entry)
                                ||      (!zval_is_true(*entry)))) {
                                MAKE_STD_ZVAL(pcb);
                                array_init(pcb);
@@ -612,7 +648,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
                }
 
                UPD_PROP(long, responseCode, msg->http.info.response.code);
-               UPD_PROP(string, responseStatus, msg->http.info.response.status);
+               UPD_PROP(string, responseStatus, msg->http.info.response.status ? msg->http.info.response.status : "");
 
                MAKE_STD_ZVAL(resp);
                array_init(resp);
@@ -667,23 +703,33 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
                ret = FAILURE;
        }
        
-       if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
+       if (!EG(exception) && zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
                zval *param;
                
                MAKE_STD_ZVAL(param);
                ZVAL_BOOL(param, ret == SUCCESS);
-               zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
+               with_error_handling(EH_NORMAL, NULL) {
+                       zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
+               } end_error_handling();
                zval_ptr_dtor(&param);
        }
        
        return ret;
 }
 
-#define http_request_object_set_options_subr(key, ow) \
-       _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow))
-static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite)
+static int apply_pretty_key(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
+{
+       if (hash_key->nKeyLength > 1) {
+               hash_key->h = zend_get_hash_value(pretty_key(hash_key->arKey, hash_key->nKeyLength - 1, 1, 0), hash_key->nKeyLength);
+       }
+       return ZEND_HASH_APPLY_KEEP;
+}
+
+#define http_request_object_set_options_subr(key, ow, pk) \
+       _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow), (pk))
+static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite, int prettify_keys)
 {
-       zval *old_opts, *new_opts, *opts = NULL, **entry;
+       zval *old_opts, *new_opts, *opts = NULL, **entry = NULL;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) {
                RETURN_FALSE;
@@ -696,7 +742,10 @@ static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM
                array_copy(old_opts, new_opts);
        }
 
-       if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void **) &entry)) {
+       if (prettify_keys && opts) {
+               zend_hash_apply_with_arguments(Z_ARRVAL_P(opts), apply_pretty_key, 0);
+       }
+       if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void *) &entry)) {
                if (overwrite) {
                        zend_hash_clean(Z_ARRVAL_PP(entry));
                }
@@ -723,14 +772,14 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS,
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                zval *opts, **options;
 
                opts = GET_PROP(options);
                array_init(return_value);
 
                if (    (Z_TYPE_P(opts) == IS_ARRAY) && 
-                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options))) {
+                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void *) &options))) {
                        convert_to_array(*options);
                        array_copy(*options, return_value);
                }
@@ -851,7 +900,7 @@ PHP_METHOD(HttpRequest, getOptions)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(options);
        }
 }
@@ -868,7 +917,7 @@ PHP_METHOD(HttpRequest, getOptions)
  */
 PHP_METHOD(HttpRequest, setSslOptions)
 {
-       http_request_object_set_options_subr("ssl", 1);
+       http_request_object_set_options_subr("ssl", 1, 0);
 }
 /* }}} */
 
@@ -882,7 +931,7 @@ PHP_METHOD(HttpRequest, setSslOptions)
  */
 PHP_METHOD(HttpRequest, addSslOptions)
 {
-       http_request_object_set_options_subr("ssl", 0);
+       http_request_object_set_options_subr("ssl", 0, 0);
 }
 /* }}} */
 
@@ -909,7 +958,7 @@ PHP_METHOD(HttpRequest, getSslOptions)
  */
 PHP_METHOD(HttpRequest, addHeaders)
 {
-       http_request_object_set_options_subr("headers", 0);
+       http_request_object_set_options_subr("headers", 0, 1);
 }
 
 /* {{{ proto bool HttpRequest::setHeaders([array headers])
@@ -923,7 +972,7 @@ PHP_METHOD(HttpRequest, addHeaders)
  */
 PHP_METHOD(HttpRequest, setHeaders)
 {
-       http_request_object_set_options_subr("headers", 1);
+       http_request_object_set_options_subr("headers", 1, 1);
 }
 /* }}} */
 
@@ -950,7 +999,7 @@ PHP_METHOD(HttpRequest, getHeaders)
  */
 PHP_METHOD(HttpRequest, setCookies)
 {
-       http_request_object_set_options_subr("cookies", 1);
+       http_request_object_set_options_subr("cookies", 1, 0);
 }
 /* }}} */
 
@@ -965,7 +1014,7 @@ PHP_METHOD(HttpRequest, setCookies)
  */
 PHP_METHOD(HttpRequest, addCookies)
 {
-       http_request_object_set_options_subr("cookies", 0);
+       http_request_object_set_options_subr("cookies", 0, 0);
 }
 /* }}} */
 
@@ -1013,7 +1062,7 @@ PHP_METHOD(HttpRequest, getUrl)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(url);
        }
 }
@@ -1051,7 +1100,7 @@ PHP_METHOD(HttpRequest, getMethod)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(method);
        }
 }
@@ -1076,7 +1125,9 @@ PHP_METHOD(HttpRequest, setContentType)
                RETURN_FALSE;
        }
 
-       HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
+       if (ct_len) {
+               HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
+       }
        UPD_STRL(contentType, ctype, ct_len);
        RETURN_TRUE;
 }
@@ -1092,7 +1143,7 @@ PHP_METHOD(HttpRequest, getContentType)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(contentType);
        }
 }
@@ -1151,7 +1202,7 @@ PHP_METHOD(HttpRequest, getQueryData)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(queryData);
        }
 }
@@ -1263,7 +1314,7 @@ PHP_METHOD(HttpRequest, getPostFields)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(postFields);
        }
 }
@@ -1343,7 +1394,7 @@ PHP_METHOD(HttpRequest, getRawPostData)
 {
        NO_ARGS;
        
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(rawPostData);
        }
 }
@@ -1441,7 +1492,7 @@ PHP_METHOD(HttpRequest, getPostFiles)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(postFiles);
        }
 }
@@ -1480,7 +1531,7 @@ PHP_METHOD(HttpRequest, getPutFile)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(putFile);
        }
 }
@@ -1535,8 +1586,6 @@ PHP_METHOD(HttpRequest, addPutData)
        }
        
        if (data_len) {
-               char *new_data;
-               size_t new_data_len;
                zval *data = GET_PROP(putData);
                
                if (Z_STRLEN_P(data)) {
@@ -1562,7 +1611,7 @@ PHP_METHOD(HttpRequest, getPutData)
 {
        NO_ARGS;
        
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(putData);
        }
 }
@@ -1583,7 +1632,7 @@ PHP_METHOD(HttpRequest, getResponseData)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(responseData);
        }
 }
@@ -1604,7 +1653,7 @@ PHP_METHOD(HttpRequest, getResponseData)
  */
 PHP_METHOD(HttpRequest, getResponseHeader)
 {
-       IF_RETVAL_USED {
+       if (return_value_used) {
                zval *data, **headers, **header;
                char *header_name = NULL;
                int header_len = 0;
@@ -1615,11 +1664,11 @@ PHP_METHOD(HttpRequest, getResponseHeader)
 
                data = GET_PROP(responseData);
                if (    (Z_TYPE_P(data) == IS_ARRAY) && 
-                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) &&
+                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void *) &headers)) &&
                                (Z_TYPE_PP(headers) == IS_ARRAY)) {
                        if (!header_len || !header_name) {
                                RETVAL_ZVAL(*headers, 1, 0);
-                       } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) {
+                       } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void *) &header)) {
                                RETVAL_ZVAL(*header, 1, 0);
                        } else {
                                RETVAL_FALSE;
@@ -1642,7 +1691,7 @@ PHP_METHOD(HttpRequest, getResponseHeader)
  */
 PHP_METHOD(HttpRequest, getResponseCookies)
 {
-       IF_RETVAL_USED {
+       if (return_value_used) {
                long flags = 0;
                zval *allowed_extras_array = NULL, *data, **headers;
 
@@ -1652,7 +1701,7 @@ PHP_METHOD(HttpRequest, getResponseCookies)
 
                data = GET_PROP(responseData);
                if (    (Z_TYPE_P(data) == IS_ARRAY) &&
-                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) &&
+                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void *) &headers)) &&
                                (Z_TYPE_PP(headers) == IS_ARRAY)) {
                        int i = 0;
                        ulong idx = 0;
@@ -1738,12 +1787,12 @@ PHP_METHOD(HttpRequest, getResponseBody)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                zval **body;
                zval *data = GET_PROP(responseData);
                
                if (    (Z_TYPE_P(data) == IS_ARRAY) && 
-                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body))) {
+                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void *) &body))) {
                        RETURN_ZVAL(*body, 1, 0);
                } else {
                        RETURN_FALSE;
@@ -1765,7 +1814,7 @@ PHP_METHOD(HttpRequest, getResponseCode)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(responseCode);
        }
 }
@@ -1781,7 +1830,7 @@ PHP_METHOD(HttpRequest, getResponseStatus)
 {
        NO_ARGS;
        
-       IF_RETVAL_USED {
+       if (return_value_used) {
                RETURN_PROP(responseStatus);
        }
 }
@@ -1805,7 +1854,7 @@ PHP_METHOD(HttpRequest, getResponseStatus)
  */
 PHP_METHOD(HttpRequest, getResponseInfo)
 {
-       IF_RETVAL_USED {
+       if (return_value_used) {
                zval *info, **infop;
                char *info_name = NULL;
                int info_len = 0;
@@ -1821,7 +1870,7 @@ PHP_METHOD(HttpRequest, getResponseInfo)
                }
 
                if (info_len && info_name) {
-                       if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) {
+                       if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) {
                                RETURN_ZVAL(*infop, 1, 0);
                        } else {
                                http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Could not find response info named %s", info_name);
@@ -1845,13 +1894,11 @@ PHP_METHOD(HttpRequest, getResponseInfo)
  * to access the data of previously received responses within this request
  * cycle.
  * 
- * Throws HttpException.
+ * Throws HttpException, HttpRuntimeException.
  */
 PHP_METHOD(HttpRequest, getResponseMessage)
 {
-       NO_ARGS;
-
-       IF_RETVAL_USED {
+       NO_ARGS {
                zval *message;
 
                SET_EH_THROW_HTTP();
@@ -1859,7 +1906,7 @@ PHP_METHOD(HttpRequest, getResponseMessage)
                if (Z_TYPE_P(message) == IS_OBJECT) {
                        RETVAL_OBJECT(message, 1);
                } else {
-                       RETVAL_NULL();
+                       http_error(HE_WARNING, HTTP_E_RUNTIME, "HttpRequest does not contain a response message");
                }
                SET_EH_NORMAL();
        }
@@ -1888,7 +1935,7 @@ PHP_METHOD(HttpRequest, getRequestMessage)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                http_message *msg;
                getObject(http_request_object, obj);
 
@@ -1906,13 +1953,12 @@ PHP_METHOD(HttpRequest, getRequestMessage)
  * Get sent HTTP message.
  * 
  * Returns an HttpMessage in a form of a string 
- * 
  */
 PHP_METHOD(HttpRequest, getRawRequestMessage)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                getObject(http_request_object, obj);
 
                RETURN_PHPSTR_DUP(&obj->request->conv.request);
@@ -1925,13 +1971,12 @@ PHP_METHOD(HttpRequest, getRawRequestMessage)
  * Get the entire HTTP response.
  * 
  * Returns the complete web server response, including the headers in a form of a string.
- * 
  */
 PHP_METHOD(HttpRequest, getRawResponseMessage)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                getObject(http_request_object, obj);
 
                RETURN_PHPSTR_DUP(&obj->request->conv.response);
@@ -1958,7 +2003,7 @@ PHP_METHOD(HttpRequest, getHistory)
 {
        NO_ARGS;
 
-       IF_RETVAL_USED {
+       if (return_value_used) {
                zval *hist;
                
                SET_EH_THROW_HTTP();