From: Michael Wallner Date: Tue, 14 Feb 2006 13:53:00 +0000 (+0000) Subject: - reset request->_error X-Git-Tag: RELEASE_0_23_0~6 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=96c0ae82ca8cda98d70b87597d765a9d050129de - reset request->_error - 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 --- diff --git a/http_request_api.c b/http_request_api.c index 3fa73e2..d07305e 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -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"); diff --git a/http_request_object.c b/http_request_object.c index b19cde3..2ab84c0 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -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(¶m); + } + + 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);