- reset request->_error
authorMichael Wallner <mike@php.net>
Tue, 14 Feb 2006 13:53:00 +0000 (13:53 +0000)
committerMichael Wallner <mike@php.net>
Tue, 14 Feb 2006 13:53:00 +0000 (13:53 +0000)
- add request->_error to info array
- update HttpRequest properties with empty values on failed request
- always fetch request info with HttpRequest
- append request message to history on failed  request
- call HttpRequest::onFinish even on failure with a bool param indicating success

http_request_api.c
http_request_object.c

index 3fa73e217e6c6ebe9d651ab3ee3eded5981399a1..d07305e6930fb84e51fe953af5ca781f18534623 100644 (file)
@@ -412,6 +412,7 @@ PHP_HTTP_API void _http_request_reset(http_request *request)
        if (request->ch) {
                http_request_defaults(request);
        }
+       request->_error[0] = '\0';
 }
 /* }}} */
 
@@ -872,6 +873,7 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
        HTTP_CURL_INFO(CURLINFO_HTTPAUTH_AVAIL);
        HTTP_CURL_INFO(CURLINFO_PROXYAUTH_AVAIL);
        HTTP_CURL_INFO(CURLINFO_OS_ERRNO);
+       add_assoc_string(&array, "error", request->_error, 1);
        HTTP_CURL_INFO(CURLINFO_NUM_CONNECTS);
 #if LIBCURL_VERSION_NUM >= 0x070e01
        HTTP_CURL_INFO_EX(CURLINFO_COOKIELIST, "cookies");
index b19cde363915b91e3c1748b8ce9bcec5803af9f1..2ab84c0c3fe0300efbe271254a58be09e62d6b3f 100644 (file)
@@ -551,19 +551,25 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
 
 STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
 {
+       STATUS ret;
+       zval *info;
        http_message *msg;
        
+       /* always fetch info */
+       MAKE_STD_ZVAL(info);
+       array_init(info);
+       http_request_info(obj->request, Z_ARRVAL_P(info));
+       SET_PROP(responseInfo, info);
+       zval_ptr_dtor(&info);
+       
+       /* parse response message */
        phpstr_fix(&obj->request->conv.request);
        phpstr_fix(&obj->request->conv.response);
        
-       msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response));
-       
-       if (!msg) {
-               return FAILURE;
-       } else {
+       if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response)))) {
                char *body;
                size_t body_len;
-               zval *headers, *message, *resp, *info;
+               zval *headers, *message, *resp;
 
                if (zval_is_true(GET_PROP(recordHistory))) {
                        /* we need to act like a zipper, as we'll receive
@@ -642,18 +648,53 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this
                SET_PROP(responseMessage, message);
                zval_ptr_dtor(&message);
 
-               MAKE_STD_ZVAL(info);
-               array_init(info);
-               http_request_info(obj->request, Z_ARRVAL_P(info));
-               SET_PROP(responseInfo, info);
-               zval_ptr_dtor(&info);
+               ret = SUCCESS;
+       } else {
+               /* update properties with empty values*/
+               zval *resp = GET_PROP(responseData), *znull;
+               
+               MAKE_STD_ZVAL(znull);
+               ZVAL_NULL(znull);
+               SET_PROP(responseMessage, znull);
+               zval_ptr_dtor(&znull);
                
-               if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
-                       zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL);
+               if (Z_TYPE_P(resp) == IS_ARRAY) {
+                       zend_hash_clean(Z_ARRVAL_P(resp));
                }
                
-               return SUCCESS;
+               UPD_PROP(long, responseCode, 0);
+               UPD_PROP(string, responseStatus, "");
+               
+               /* append request message to history */
+               if (zval_is_true(GET_PROP(recordHistory))) {
+                       http_message *request;
+                       
+                       if ((request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
+                               zval *hist, *history = GET_PROP(history);
+                               
+                               MAKE_STD_ZVAL(hist);
+                               ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, request, NULL), 0);
+                               if (Z_TYPE_P(history) == IS_OBJECT) {
+                                       http_message_object_prepend(hist, history);
+                               }
+                               SET_PROP(history, hist);
+                               zval_ptr_dtor(&hist);
+                       }
+               }
+               
+               ret = FAILURE;
        }
+       
+       if (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);
+               zval_ptr_dtor(&param);
+       }
+       
+       return ret;
 }
 
 #define http_request_object_set_options_subr(key, ow) \
@@ -1571,7 +1612,6 @@ PHP_METHOD(HttpRequest, getResponseCookies)
                                        
                                        if (Z_TYPE_PP(header) == IS_ARRAY) {
                                                zval **single_header;
-                                               HashPosition pos;
                                                
                                                FOREACH_VAL(pos2, *header, single_header) {
                                                        ZVAL_ADDREF(*single_header);