X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=dc83d236fa83e38fcf7c9786673c7bb3367a024b;hb=e6b35fbe072a13b0e792952852fcd1499bd8e610;hp=308212c5120a51646e6642679c1455ff796fc737;hpb=eeb93322c9e734419c7d671a7806cbd0df4109a5;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index 308212c..dc83d23 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)); + } } } }