- spawn off http_cookie_api
[m6w6/ext-http] / http_request_object.c
index 7eb00d493809e176c1bce075413d84f364113529..93ce0109fa35f9f7dcfd62db3797ffa92c3968f2 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
@@ -24,6 +20,7 @@
 #include "zend_interfaces.h"
 
 #include "php_http_api.h"
+#include "php_http_cookie_api.h"
 #include "php_http_exception_object.h"
 #include "php_http_message_api.h"
 #include "php_http_message_object.h"
 #include "php_http_request_pool_api.h"
 #include "php_http_url_api.h"
 
-#define HTTP_BEGIN_ARGS(method, ret_ref, req_args)     HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args)
-#define HTTP_EMPTY_ARGS(method, ret_ref)                       HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref)
-#define HTTP_REQUEST_ME(method, visibility)                    PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
-#define HTTP_REQUEST_ALIAS(method, func)                       HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
+#define HTTP_BEGIN_ARGS(method, req_args)      HTTP_BEGIN_ARGS_EX(HttpRequest, method, 0, req_args)
+#define HTTP_EMPTY_ARGS(method)                                HTTP_EMPTY_ARGS_EX(HttpRequest, method, 0)
+#define HTTP_REQUEST_ME(method, visibility)    PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
+#define HTTP_REQUEST_ALIAS(method, func)       HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
 
-HTTP_BEGIN_ARGS(__construct, 0, 0)
+HTTP_BEGIN_ARGS(__construct, 0)
        HTTP_ARG_VAL(url, 0)
        HTTP_ARG_VAL(method, 0)
        HTTP_ARG_VAL(options, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getOptions, 0);
-HTTP_BEGIN_ARGS(setOptions, 0, 0)
+HTTP_EMPTY_ARGS(getOptions);
+HTTP_BEGIN_ARGS(setOptions, 0)
        HTTP_ARG_VAL(options, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getSslOptions, 0);
-HTTP_BEGIN_ARGS(setSslOptions, 0, 0)
+HTTP_EMPTY_ARGS(getSslOptions);
+HTTP_BEGIN_ARGS(setSslOptions, 0)
        HTTP_ARG_VAL(ssl_options, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addSslOptions, 0, 0)
+HTTP_BEGIN_ARGS(addSslOptions, 0)
        HTTP_ARG_VAL(ssl_optins, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getHeaders, 0);
-HTTP_BEGIN_ARGS(setHeaders, 0, 0)
+HTTP_EMPTY_ARGS(getHeaders);
+HTTP_BEGIN_ARGS(setHeaders, 0)
        HTTP_ARG_VAL(headers, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addHeaders, 0, 1)
+HTTP_BEGIN_ARGS(addHeaders, 1)
        HTTP_ARG_VAL(headers, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getCookies, 0);
-HTTP_BEGIN_ARGS(setCookies, 0, 0)
+HTTP_EMPTY_ARGS(getCookies);
+HTTP_BEGIN_ARGS(setCookies, 0)
        HTTP_ARG_VAL(cookies, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addCookies, 0, 1)
+HTTP_BEGIN_ARGS(addCookies, 1)
        HTTP_ARG_VAL(cookies, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getUrl, 0);
-HTTP_BEGIN_ARGS(setUrl, 0, 1)
+HTTP_EMPTY_ARGS(getUrl);
+HTTP_BEGIN_ARGS(setUrl, 1)
        HTTP_ARG_VAL(url, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getMethod, 0);
-HTTP_BEGIN_ARGS(setMethod, 0, 1)
+HTTP_EMPTY_ARGS(getMethod);
+HTTP_BEGIN_ARGS(setMethod, 1)
        HTTP_ARG_VAL(request_method, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getContentType, 0);
-HTTP_BEGIN_ARGS(setContentType, 0, 1)
+HTTP_EMPTY_ARGS(getContentType);
+HTTP_BEGIN_ARGS(setContentType, 1)
        HTTP_ARG_VAL(content_type, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getQueryData, 0);
-HTTP_BEGIN_ARGS(setQueryData, 0, 0)
+HTTP_EMPTY_ARGS(getQueryData);
+HTTP_BEGIN_ARGS(setQueryData, 0)
        HTTP_ARG_VAL(query_data, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addQueryData, 0, 1)
+HTTP_BEGIN_ARGS(addQueryData, 1)
        HTTP_ARG_VAL(query_data, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getPostFields, 0);
-HTTP_BEGIN_ARGS(setPostFields, 0, 0)
+HTTP_EMPTY_ARGS(getPostFields);
+HTTP_BEGIN_ARGS(setPostFields, 0)
        HTTP_ARG_VAL(post_fields, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addPostFields, 0, 1)
+HTTP_BEGIN_ARGS(addPostFields, 1)
        HTTP_ARG_VAL(post_fields, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getPostFiles, 0);
-HTTP_BEGIN_ARGS(setPostFiles, 0, 0)
+HTTP_EMPTY_ARGS(getPostFiles);
+HTTP_BEGIN_ARGS(setPostFiles, 0)
        HTTP_ARG_VAL(post_files, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addPostFile, 0, 2)
+HTTP_BEGIN_ARGS(addPostFile, 2)
        HTTP_ARG_VAL(formname, 0)
        HTTP_ARG_VAL(filename, 0)
        HTTP_ARG_VAL(content_type, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getRawPostData, 0);
-HTTP_BEGIN_ARGS(setRawPostData, 0, 0)
+HTTP_EMPTY_ARGS(getRawPostData);
+HTTP_BEGIN_ARGS(setRawPostData, 0)
        HTTP_ARG_VAL(raw_post_data, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addRawPostData, 0, 1)
+HTTP_BEGIN_ARGS(addRawPostData, 1)
        HTTP_ARG_VAL(raw_post_data, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getPutFile, 0);
-HTTP_BEGIN_ARGS(setPutFile, 0, 0)
+HTTP_EMPTY_ARGS(getPutFile);
+HTTP_BEGIN_ARGS(setPutFile, 0)
        HTTP_ARG_VAL(filename, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getResponseData, 0);
-HTTP_BEGIN_ARGS(getResponseHeader, 0, 0)
+HTTP_EMPTY_ARGS(getResponseData);
+HTTP_BEGIN_ARGS(getResponseHeader, 0)
        HTTP_ARG_VAL(name, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(getResponseCookie, 0, 0)
-       HTTP_ARG_VAL(name, 0)
+HTTP_BEGIN_ARGS(getResponseCookies, 0)
+       HTTP_ARG_VAL(flags, 0)
+       HTTP_ARG_VAL(allowed_extras, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getResponseBody, 0);
-HTTP_EMPTY_ARGS(getResponseCode, 0);
-HTTP_BEGIN_ARGS(getResponseInfo, 0, 0)
+HTTP_EMPTY_ARGS(getResponseBody);
+HTTP_EMPTY_ARGS(getResponseCode);
+HTTP_EMPTY_ARGS(getResponseStatus);
+HTTP_BEGIN_ARGS(getResponseInfo, 0)
        HTTP_ARG_VAL(name, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getResponseMessage, 0);
-HTTP_EMPTY_ARGS(getRawResponseMessage, 0);
-HTTP_EMPTY_ARGS(getRequestMessage, 0);
-HTTP_EMPTY_ARGS(getRawRequestMessage, 0);
-HTTP_EMPTY_ARGS(getHistory, 0);
-HTTP_EMPTY_ARGS(clearHistory, 0);
-HTTP_EMPTY_ARGS(send, 0);
+HTTP_EMPTY_ARGS(getResponseMessage);
+HTTP_EMPTY_ARGS(getRawResponseMessage);
+HTTP_EMPTY_ARGS(getRequestMessage);
+HTTP_EMPTY_ARGS(getRawRequestMessage);
+HTTP_EMPTY_ARGS(getHistory);
+HTTP_EMPTY_ARGS(clearHistory);
+HTTP_EMPTY_ARGS(send);
 
-HTTP_BEGIN_ARGS(get, 0, 1)
+HTTP_BEGIN_ARGS(get, 1)
        HTTP_ARG_VAL(url, 0)
        HTTP_ARG_VAL(options, 0)
        HTTP_ARG_VAL(info, 1)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(head, 0, 1)
+HTTP_BEGIN_ARGS(head, 1)
        HTTP_ARG_VAL(url, 0)
        HTTP_ARG_VAL(options, 0)
        HTTP_ARG_VAL(info, 1)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(postData, 0, 2)
+HTTP_BEGIN_ARGS(postData, 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(postFields, 0, 2)
+HTTP_BEGIN_ARGS(postFields, 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, 0, 2)
+HTTP_BEGIN_ARGS(putFile, 2)
        HTTP_ARG_VAL(url, 0)
        HTTP_ARG_VAL(file, 0)
        HTTP_ARG_VAL(options, 0)
        HTTP_ARG_VAL(info, 1)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(putStream, 0, 2)
+HTTP_BEGIN_ARGS(putStream, 2)
        HTTP_ARG_VAL(url, 0)
        HTTP_ARG_VAL(stream, 0)
        HTTP_ARG_VAL(options, 0)
        HTTP_ARG_VAL(info, 1)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(methodRegister, 0, 1)
+HTTP_BEGIN_ARGS(methodRegister, 1)
        HTTP_ARG_VAL(method_name, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(methodUnregister, 0, 1)
+HTTP_BEGIN_ARGS(methodUnregister, 1)
        HTTP_ARG_VAL(method, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(methodName, 0, 1)
+HTTP_BEGIN_ARGS(methodName, 1)
        HTTP_ARG_VAL(method_id, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(methodExists, 0, 1)
+HTTP_BEGIN_ARGS(methodExists, 1)
        HTTP_ARG_VAL(method, 0)
 HTTP_END_ARGS;
 
@@ -266,8 +265,9 @@ zend_function_entry http_request_object_fe[] = {
 
        HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC)
-       HTTP_REQUEST_ME(getResponseCookie, ZEND_ACC_PUBLIC)
+       HTTP_REQUEST_ME(getResponseCookies, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getResponseCode, ZEND_ACC_PUBLIC)
+       HTTP_REQUEST_ME(getResponseStatus, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getResponseBody, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC)
@@ -302,7 +302,7 @@ PHP_MINIT_FUNCTION(http_request_object)
 
 zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
 {
-       return http_request_object_new_ex(ce, curl_easy_init(), NULL);
+       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)
@@ -337,7 +337,10 @@ zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
        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, curl_easy_duphandle(old_obj->request->ch), &new_obj);
+       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->history, old_obj->history.data, old_obj->history.used);
@@ -358,6 +361,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
        DCL_PROP_N(PRIVATE, responseData);
        DCL_PROP_N(PRIVATE, responseMessage);
        DCL_PROP(PRIVATE, long, responseCode, 0);
+       DCL_PROP(PRIVATE, string, responseStatus, "");
        DCL_PROP(PRIVATE, long, method, HTTP_GET);
        DCL_PROP(PRIVATE, string, url, "");
        DCL_PROP(PRIVATE, string, contentType, "");
@@ -403,6 +407,11 @@ 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 */
+       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
         */
@@ -431,7 +440,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
        STATUS status = SUCCESS;
 
        http_request_reset(obj->request);
-       HTTP_CHECK_CURL_INIT(obj->request->ch, curl_easy_init(), return FAILURE);
+       HTTP_CHECK_CURL_INIT(obj->request->ch, http_curl_init(obj->request), return FAILURE);
        
        obj->request->url = http_absolute_url(Z_STRVAL_P(GET_PROP(url)));
        
@@ -497,8 +506,10 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                                fields = (Z_TYPE_P(zfields) == IS_ARRAY) ? Z_ARRVAL_P(zfields) : NULL;
                                files = (Z_TYPE_P(zfiles) == IS_ARRAY) ? Z_ARRVAL_P(zfiles) : NULL;
                                
-                               if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) {
-                                       status = FAILURE;
+                               if ((fields && zend_hash_num_elements(fields)) || (files && zend_hash_num_elements(files))) {
+                                       if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) {
+                                               status = FAILURE;
+                                       }
                                }
                        }
                }
@@ -584,6 +595,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);
 
                MAKE_STD_ZVAL(resp);
                array_init(resp);
@@ -597,7 +609,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
                zval_ptr_dtor(&resp);
 
                MAKE_STD_ZVAL(message);
-               ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL));
+               ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL), 0);
                SET_PROP(responseMessage, message);
                zval_ptr_dtor(&message);
 
@@ -619,8 +631,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
        _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)
 {
-       zval *old_opts, *new_opts, *opts, **entry;
-       getObject(http_request_object, obj);
+       zval *old_opts, *new_opts, *opts = NULL, **entry;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) {
                RETURN_FALSE;
@@ -662,10 +673,8 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS,
 
        IF_RETVAL_USED {
                zval *opts, **options;
-               getObject(http_request_object, obj);
 
                opts = GET_PROP(options);
-
                array_init(return_value);
 
                if (    (Z_TYPE_P(opts) == IS_ARRAY) && 
@@ -684,7 +693,7 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS,
  * Instantiate a new HttpRequest object.
  * 
  * Accepts a string as optional parameter containing the target request url.
- * Additianally accepts an optional int parameter specifying the request method
+ * Additionally accepts an optional int parameter specifying the request method
  * to use and an associative array as optional third parameter which will be
  * passed to HttpRequest::setOptions(). 
  * 
@@ -696,7 +705,6 @@ PHP_METHOD(HttpRequest, __construct)
        int URL_len;
        long meth = -1;
        zval *options = NULL;
-       getObject(http_request_object, obj);
 
        SET_EH_THROW_HTTP();
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla", &URL, &URL_len, &meth, &options)) {
@@ -718,9 +726,9 @@ PHP_METHOD(HttpRequest, __construct)
  *
  * Set the request options to use.  See http_get() for a full list of available options.
  * 
- * Accepts an array as optional parameters, wich values will overwrite the 
- * currently set request options.  If the parameter is empty or mitted,
- * the optoions of the HttpRequest object will be reset.
+ * Accepts an array as optional parameters, which values will overwrite the 
+ * currently set request options.  If the parameter is empty or omitted,
+ * the options of the HttpRequest object will be reset.
  * 
  * Returns TRUE on success, or FALSE on failure.
  */
@@ -730,7 +738,6 @@ PHP_METHOD(HttpRequest, setOptions)
        ulong idx = 0;
        HashPosition pos;
        zval *opts = NULL, *old_opts, *new_opts, *add_opts, **opt;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
                RETURN_FALSE;
@@ -843,7 +850,7 @@ PHP_METHOD(HttpRequest, getSslOptions)
  *
  * Add request header name/value pairs.
  * 
- * Expects an ssociative array as parameter containing additional header
+ * Expects an associative array as parameter containing additional header
  * name/value pairs.
  * 
  * Returns TRUE on success, or FALSE on failure.
@@ -934,7 +941,6 @@ PHP_METHOD(HttpRequest, setUrl)
 {
        char *URL = NULL;
        int URL_len;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) {
                RETURN_FALSE;
@@ -973,7 +979,6 @@ PHP_METHOD(HttpRequest, getUrl)
 PHP_METHOD(HttpRequest, setMethod)
 {
        long meth;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) {
                RETURN_FALSE;
@@ -1014,7 +1019,6 @@ PHP_METHOD(HttpRequest, setContentType)
 {
        char *ctype;
        int ct_len;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) {
                RETURN_FALSE;
@@ -1056,7 +1060,6 @@ PHP_METHOD(HttpRequest, getContentType)
 PHP_METHOD(HttpRequest, setQueryData)
 {
        zval *qdata = NULL;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
                RETURN_FALSE;
@@ -1116,7 +1119,6 @@ PHP_METHOD(HttpRequest, addQueryData)
        zval *qdata, *old_qdata;
        char *query_data = NULL;
        size_t query_data_len = 0;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &qdata)) {
                RETURN_FALSE;
@@ -1148,7 +1150,6 @@ PHP_METHOD(HttpRequest, addQueryData)
 PHP_METHOD(HttpRequest, addPostFields)
 {
        zval *post_data, *old_post, *new_post;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &post_data)) {
                RETURN_FALSE;
@@ -1183,7 +1184,6 @@ PHP_METHOD(HttpRequest, addPostFields)
 PHP_METHOD(HttpRequest, setPostFields)
 {
        zval *post, *post_data = NULL;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &post_data)) {
                RETURN_FALSE;
@@ -1233,7 +1233,6 @@ PHP_METHOD(HttpRequest, setRawPostData)
 {
        char *raw_data = NULL;
        int data_len = 0;
-       getObject(http_request_object, obj);
        
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) {
                RETURN_FALSE;
@@ -1261,7 +1260,6 @@ PHP_METHOD(HttpRequest, addRawPostData)
 {
        char *raw_data;
        int data_len;
-       getObject(http_request_object, obj);
        
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) {
                RETURN_FALSE;
@@ -1299,12 +1297,12 @@ PHP_METHOD(HttpRequest, getRawPostData)
 
 /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
  *
- * Add a file to the POST request, leaving prefiously set files unchanged.
+ * Add a file to the POST request, leaving previously set files unchanged.
  * Affects only POST and custom requests. Cannot be used with raw post data.
  * 
  * Expects a string parameter containing the form element name, and a string
  * paremeter containing the path to the file which should be uploaded.
- * Additionally accepts an optional string parameter which chould contain
+ * Additionally accepts an optional string parameter which should contain
  * the content type of the file.
  * 
  * Returns TRUE on success, or FALSE if the content type seems not to contain a 
@@ -1315,7 +1313,6 @@ PHP_METHOD(HttpRequest, addPostFile)
        zval *entry, *old_post, *new_post;
        char *name, *file, *type = NULL;
        int name_len, file_len, type_len = 0;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) {
                RETURN_FALSE;
@@ -1363,7 +1360,6 @@ PHP_METHOD(HttpRequest, addPostFile)
 PHP_METHOD(HttpRequest, setPostFiles)
 {
        zval *files = NULL, *post;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!/", &files)) {
                RETURN_FALSE;
@@ -1410,7 +1406,6 @@ PHP_METHOD(HttpRequest, setPutFile)
 {
        char *file = "";
        int file_len = 0;
-       getObject(http_request_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file, &file_len)) {
                RETURN_FALSE;
@@ -1442,7 +1437,7 @@ PHP_METHOD(HttpRequest, getPutFile)
  * Get all response data after the request has been sent.
  * 
  * Returns an associative array with the key "headers" containing an associative
- * array holding all response headers, as well as the ley "body" containing a
+ * array holding all response headers, as well as the key "body" containing a
  * string with the response body.  
  * 
  * If redirects were allowed and several responses were received, the data 
@@ -1466,7 +1461,7 @@ PHP_METHOD(HttpRequest, getResponseData)
  * If the parameter is empty or omitted all response headers will be returned.
  * 
  * Returns either a string with the value of the header matching name if requested, 
- * FALSE on failure, or an associative array containing all reponse headers.
+ * FALSE on failure, or an associative array containing all response headers.
  * 
  * If redirects were allowed and several responses were received, the data 
  * references the last received response.
@@ -1477,7 +1472,6 @@ PHP_METHOD(HttpRequest, getResponseHeader)
                zval *data, **headers, **header;
                char *header_name = NULL;
                int header_len = 0;
-               getObject(http_request_object, obj);
 
                if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) {
                        RETURN_FALSE;
@@ -1501,108 +1495,97 @@ PHP_METHOD(HttpRequest, getResponseHeader)
 }
 /* }}} */
 
-/* {{{ proto array HttpRequest::getResponseCookie([string name])
+/* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]])
  *
  * Get response cookie(s) after the request has been sent.
  * 
- * Accepts a string as optional parameter specifying the name of the cookie to read.
- * If the parameter is empty or omitted, an associative array with all received
- * cookies will be returned.
- * 
- * Returns either an associative array with the cookie's name, value and any
- * additional params of the cookie matching name if requested, FALSE on failure,
- * or an array containing all received cookies as arrays.
+ * Returns an array of stdClass objects like http_parse_cookie would return.
  * 
  * If redirects were allowed and several responses were received, the data 
  * references the last received response.
  */
-PHP_METHOD(HttpRequest, getResponseCookie)
+PHP_METHOD(HttpRequest, getResponseCookies)
 {
        IF_RETVAL_USED {
-               zval *data, **headers;
-               char *cookie_name = NULL;
-               int cookie_len = 0;
-               getObject(http_request_object, obj);
+               long flags = 0;
+               zval *allowed_extras_array = NULL, *data, **headers;
 
-               if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cookie_name, &cookie_len)) {
+               if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la", &flags, &allowed_extras_array)) {
                        RETURN_FALSE;
                }
 
-               array_init(return_value);
-
                data = GET_PROP(responseData);
                if (    (Z_TYPE_P(data) == IS_ARRAY) &&
                                (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;
-                       char *key = NULL;
-                       zval **header = NULL;
-                       HashPosition pos1;
-
+                       char *key = NULL, **allowed_extras = NULL;
+                       zval **header = NULL, **entry = NULL;
+                       HashPosition pos, pos1, pos2;
+                       
+                       array_init(return_value);
+
+                       if (allowed_extras_array) {
+                               allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
+                               FOREACH_VAL(pos, allowed_extras_array, entry) {
+                                       ZVAL_ADDREF(*entry);
+                                       convert_to_string_ex(entry);
+                                       allowed_extras[i++] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
+                                       zval_ptr_dtor(entry);
+                               }
+                       }
+                       
                        convert_to_array(*headers);
                        FOREACH_HASH_KEYVAL(pos1, Z_ARRVAL_PP(headers), key, idx, header) {
                                if (key && !strcasecmp(key, "Set-Cookie")) {
-                                       /* several cookies? */
+                                       http_cookie_list list;
+                                       
                                        if (Z_TYPE_PP(header) == IS_ARRAY) {
-                                               zval **cookie;
-                                               HashPosition pos2;
-
-                                               FOREACH_HASH_VAL(pos2, Z_ARRVAL_PP(header), cookie) {
-                                                       zval *cookie_hash;
-                                                       MAKE_STD_ZVAL(cookie_hash);
-                                                       array_init(cookie_hash);
-
-                                                       if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(cookie), Z_ARRVAL_P(cookie_hash))) {
-                                                               if (!cookie_len) {
-                                                                       add_next_index_zval(return_value, cookie_hash);
-                                                               } else {
-                                                                       zval **name;
-
-                                                                       if (    (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) &&
-                                                                                       (!strcmp(Z_STRVAL_PP(name), cookie_name))) {
-                                                                               add_next_index_zval(return_value, cookie_hash);
-                                                                               return; /* <<< FOUND >>> */
-                                                                       } else {
-                                                                               zval_dtor(cookie_hash);
-                                                                               efree(cookie_hash);
-                                                                       }
-                                                               }
-                                                       } else {
-                                                               zval_dtor(cookie_hash);
-                                                               efree(cookie_hash);
+                                               zval **single_header;
+                                               HashPosition pos;
+                                               
+                                               FOREACH_VAL(pos2, *header, single_header) {
+                                                       ZVAL_ADDREF(*single_header);
+                                                       convert_to_string_ex(single_header);
+                                                       if (http_parse_cookie_ex(&list, Z_STRVAL_PP(single_header), flags, allowed_extras)) {
+                                                               zval *cookie;
+                                                               
+                                                               MAKE_STD_ZVAL(cookie);
+                                                               object_init(cookie);
+                                                               http_cookie_list_tostruct(&list, cookie);
+                                                               add_next_index_zval(return_value, cookie);
+                                                               zval_ptr_dtor(&cookie);
                                                        }
+                                                       zval_ptr_dtor(single_header);
                                                }
                                        } else {
-                                               zval *cookie_hash;
-                                               
-                                               MAKE_STD_ZVAL(cookie_hash);
-                                               array_init(cookie_hash);
+                                               ZVAL_ADDREF(*header);
                                                convert_to_string_ex(header);
-                                               
-                                               if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(header), Z_ARRVAL_P(cookie_hash))) {
-                                                       if (!cookie_len) {
-                                                               add_next_index_zval(return_value, cookie_hash);
-                                                       } else {
-                                                               zval **name;
-
-                                                               if (    (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) &&
-                                                                               (!strcmp(Z_STRVAL_PP(name), cookie_name))) {
-                                                                       add_next_index_zval(return_value, cookie_hash);
-                                                               } else {
-                                                                       zval_dtor(cookie_hash);
-                                                                       efree(cookie_hash);
-                                                               }
-                                                       }
-                                               } else {
-                                                       zval_dtor(cookie_hash);
-                                                       efree(cookie_hash);
+                                               if (http_parse_cookie_ex(&list, Z_STRVAL_PP(header), flags, allowed_extras)) {
+                                                       zval *cookie;
+                                                               
+                                                       MAKE_STD_ZVAL(cookie);
+                                                       object_init(cookie);
+                                                       http_cookie_list_tostruct(&list, cookie);
+                                                       add_next_index_zval(return_value, cookie);
+                                                       zval_ptr_dtor(&cookie);
                                                }
+                                               zval_ptr_dtor(header);
                                        }
-                                       break;
                                }
                                /* reset key */
                                key = NULL;
                        }
+       
+                       if (allowed_extras) {
+                               for (i = 0; allowed_extras[i]; ++i) {
+                                       efree(allowed_extras[i]);
+                               }
+                               efree(allowed_extras);
+                       }
+               } else {
+                       RETURN_FALSE;
                }
        }
 }
@@ -1623,7 +1606,6 @@ PHP_METHOD(HttpRequest, getResponseBody)
 
        IF_RETVAL_USED {
                zval **body;
-               getObject(http_request_object, obj);
                zval *data = GET_PROP(responseData);
                
                if (    (Z_TYPE_P(data) == IS_ARRAY) && 
@@ -1655,6 +1637,22 @@ PHP_METHOD(HttpRequest, getResponseCode)
 }
 /* }}} */
 
+/* {{{ proto string HttpRequest::getResponseStatus()
+ *
+ * Get the response status (i.e. the string after the response code) after the message has been sent.
+ *
+ * Returns a string containing the response status text.
+ */
+PHP_METHOD(HttpRequest, getResponseStatus)
+{
+       NO_ARGS;
+       
+       IF_RETVAL_USED {
+               RETURN_PROP(responseStatus);
+       }
+}
+/* }}} */
+
 /* {{{ proto mixed HttpRequest::getResponseInfo([string name])
  *
  * Get response info after the request has been sent.
@@ -1677,7 +1675,6 @@ PHP_METHOD(HttpRequest, getResponseInfo)
                zval *info, **infop;
                char *info_name = NULL;
                int info_len = 0;
-               getObject(http_request_object, obj);
 
                if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
                        RETURN_FALSE;
@@ -1711,7 +1708,7 @@ PHP_METHOD(HttpRequest, getResponseInfo)
  * 
  * If redirects were allowed and several responses were received, the data 
  * references the last received response.  Use HttpMessage::getParentMessage()
- * to access the data of previously received responses whithin this request
+ * to access the data of previously received responses within this request
  * cycle.
  * 
  * Throws HttpException.
@@ -1722,12 +1719,11 @@ PHP_METHOD(HttpRequest, getResponseMessage)
 
        IF_RETVAL_USED {
                zval *message;
-               getObject(http_request_object, obj);
 
                SET_EH_THROW_HTTP();
                message = GET_PROP(responseMessage);
                if (Z_TYPE_P(message) == IS_OBJECT) {
-                       RETVAL_OBJECT(message);
+                       RETVAL_OBJECT(message, 1);
                } else {
                        RETVAL_NULL();
                }
@@ -1744,7 +1740,7 @@ PHP_METHOD(HttpRequest, getResponseMessage)
  * 
  * If redirects were allowed and several responses were received, the data 
  * references the last received response.  Use HttpMessage::getParentMessage()
- * to access the data of previously sent requests whithin this request
+ * to access the data of previously sent requests within this request
  * cycle.
  * 
  * Note that the internal request message is immutable, that means that the
@@ -1764,7 +1760,7 @@ PHP_METHOD(HttpRequest, getRequestMessage)
 
                SET_EH_THROW_HTTP();
                if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
-                       ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL));
+                       RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL), 0);
                }
                SET_EH_NORMAL();
        }
@@ -1814,7 +1810,7 @@ PHP_METHOD(HttpRequest, getRawResponseMessage)
  * Get all sent requests and received responses as an HttpMessage object.
  * 
  * If you don't want to record history at all, set the instance variable
- * HttpRequest::$recoedHistory to FALSE. 
+ * HttpRequest::$recordHistory to FALSE. 
  * 
  * Returns an HttpMessage object representing the complete request/response
  * history.
@@ -1838,7 +1834,7 @@ PHP_METHOD(HttpRequest, getHistory)
 
                SET_EH_THROW_HTTP();
                if ((msg = http_message_parse(PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history)))) {
-                       ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL));
+                       RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL), 0);
                }
                SET_EH_NORMAL();
        }
@@ -1918,7 +1914,7 @@ PHP_METHOD(HttpRequest, send)
        } else if (SUCCESS == http_request_object_requesthandler(obj, getThis())) {
                http_request_exec(obj->request);
                if (SUCCESS == http_request_object_responsehandler(obj, getThis())) {
-                       RETVAL_OBJECT(GET_PROP(responseMessage));
+                       RETVAL_OBJECT(GET_PROP(responseMessage), 1);
                }
        }