X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=3fa73e217e6c6ebe9d651ab3ee3eded5981399a1;hb=d22fd82abda2a466b68e29ae2efb93f4b4e16f19;hp=308212c5120a51646e6642679c1455ff796fc737;hpb=eeb93322c9e734419c7d671a7806cbd0df4109a5;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index 308212c..3fa73e2 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -650,9 +650,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,7 +871,7 @@ 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_OS_ERRNO); HTTP_CURL_INFO(CURLINFO_NUM_CONNECTS); #if LIBCURL_VERSION_NUM >= 0x070e01 HTTP_CURL_INFO_EX(CURLINFO_COOKIELIST, "cookies");