- reverse request history
[m6w6/ext-http] / http_request_api.c
index 308212c5120a51646e6642679c1455ff796fc737..613c32a8820ee2f82780e378aef80ec1a4f9878c 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';
 }
 /* }}} */
 
@@ -650,9 +651,37 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        if ((zoption = http_request_option(request, options, "cookies", IS_ARRAY))) {
                phpstr_dtor(&request->_cache.cookies);
                if (zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
-                       if (SUCCESS == http_urlencode_hash_recursive(HASH_OF(zoption), &request->_cache.cookies, "; ", sizeof("; ")-1, NULL, 0)) {
+                       zval *urlenc_cookies = NULL;
+                       /* check whether cookies should not be urlencoded; default is to urlencode them */
+                       if ((!(urlenc_cookies = http_request_option(request, options, "encodecookies", IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
+                               if (SUCCESS == http_urlencode_hash_recursive(HASH_OF(zoption), &request->_cache.cookies, "; ", lenof("; "), NULL, 0)) {
+                                       phpstr_fix(&request->_cache.cookies);
+                                       HTTP_CURL_OPT(CURLOPT_COOKIE, request->_cache.cookies.data);
+                               }
+                       } else {
+                               HashPosition pos;
+                               zval *cookie_val = NULL;
+                               char *cookie_key = NULL;
+                               ulong cookie_idx;
+                               
+                               FOREACH_KEY(pos, zoption, cookie_key, cookie_idx) {
+                                       if (cookie_key) {
+                                               zval **cookie_val;
+                                               if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(zoption), (void **) &cookie_val, &pos)) {
+                                                       zval *val = zval_copy(IS_STRING, *cookie_val);
+                                                       phpstr_appendf(&request->_cache.cookies, "%s=%s; ", cookie_key, Z_STRVAL_P(val));
+                                                       zval_free(&val);
+                                               }
+
+                                               /* reset */
+                                               cookie_key = NULL;
+                                       }
+                               }
+                               
                                phpstr_fix(&request->_cache.cookies);
-                               HTTP_CURL_OPT(CURLOPT_COOKIE, request->_cache.cookies.data);
+                               if (PHPSTR_LEN(&request->_cache.cookies)) {
+                                       HTTP_CURL_OPT(CURLOPT_COOKIE, PHPSTR_VAL(&request->_cache.cookies));
+                               }
                        }
                }
        }
@@ -843,11 +872,12 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
        HTTP_CURL_INFO(CURLINFO_CONTENT_TYPE);
        HTTP_CURL_INFO(CURLINFO_HTTPAUTH_AVAIL);
        HTTP_CURL_INFO(CURLINFO_PROXYAUTH_AVAIL);
-       /*HTTP_CURL_INFO(OS_ERRNO);*/
        HTTP_CURL_INFO(CURLINFO_NUM_CONNECTS);
 #if LIBCURL_VERSION_NUM >= 0x070e01
        HTTP_CURL_INFO_EX(CURLINFO_COOKIELIST, "cookies");
 #endif
+       HTTP_CURL_INFO(CURLINFO_OS_ERRNO);
+       add_assoc_string(&array, "error", request->_error, 1);
 }
 /* }}} */