- zval *zoption;
- zend_bool range_req = 0;
- php_http_request_storage_t *storage;
-
- TSRMLS_FETCH_FROM_CTX(request->ts);
-
- PHP_HTTP_CHECK_CURL_INIT(request->ch, php_http_curl_init(NULL, request TSRMLS_CC), return FAILURE);
-
- if (!(storage = php_http_request_storage_get(request->ch))) {
- return FAILURE;
- }
- storage->errorbuffer[0] = '\0';
- /* set options */
- if (storage->url) {
- pefree(storage->url, 1);
- }
- storage->url = pestrdup(request->url, 1);
- PHP_HTTP_CURL_OPT(CURLOPT_URL, storage->url);
-
- /* progress callback */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("onprogress"), -1))) {
- php_http_request_set_progress_callback(request, zoption);
- }
-
- /* proxy */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("proxyhost"), IS_STRING))) {
- PHP_HTTP_CURL_OPT(CURLOPT_PROXY, Z_STRVAL_P(zoption));
- /* type */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("proxytype"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_PROXYTYPE, Z_LVAL_P(zoption));
- }
- /* port */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("proxyport"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_PROXYPORT, Z_LVAL_P(zoption));
- }
- /* user:pass */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("proxyauth"), IS_STRING)) && Z_STRLEN_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_PROXYUSERPWD, Z_STRVAL_P(zoption));
- }
- /* auth method */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("proxyauthtype"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_PROXYAUTH, Z_LVAL_P(zoption));
- }
- /* tunnel */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("proxytunnel"), IS_BOOL)) && Z_BVAL_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_HTTPPROXYTUNNEL, 1L);
- }
- }
-#if PHP_HTTP_CURL_VERSION(7,19,4)
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("noproxy"), IS_STRING))) {
- PHP_HTTP_CURL_OPT(CURLOPT_NOPROXY, Z_STRVAL_P(zoption));
- }
-#endif
-
- /* dns */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("dns_cache_timeout"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_DNS_CACHE_TIMEOUT, Z_LVAL_P(zoption));
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("ipresolve"), IS_LONG)) && Z_LVAL_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_IPRESOLVE, Z_LVAL_P(zoption));
- }
-
- /* limits */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("low_speed_limit"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_LOW_SPEED_LIMIT, Z_LVAL_P(zoption));
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("low_speed_time"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_LOW_SPEED_TIME, Z_LVAL_P(zoption));
- }
- /* LSF weirdance
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("max_send_speed"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("max_recv_speed"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
- }
- */
- /* crashes
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("maxconnects"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_MAXCONNECTS, Z_LVAL_P(zoption));
- } */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("fresh_connect"), IS_BOOL)) && Z_BVAL_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_FRESH_CONNECT, 1L);
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("forbid_reuse"), IS_BOOL)) && Z_BVAL_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_FORBID_REUSE, 1L);
- }
-
- /* outgoing interface */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("interface"), IS_STRING))) {
- PHP_HTTP_CURL_OPT(CURLOPT_INTERFACE, Z_STRVAL_P(zoption));
-
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("portrange"), IS_ARRAY))) {
- zval **prs, **pre;
-
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption));
- if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &prs)) {
- zend_hash_move_forward(Z_ARRVAL_P(zoption));
- if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &pre)) {
- zval *prs_cpy = php_http_zsep(IS_LONG, *prs);
- zval *pre_cpy = php_http_zsep(IS_LONG, *pre);
-
- if (Z_LVAL_P(prs_cpy) && Z_LVAL_P(pre_cpy)) {
- PHP_HTTP_CURL_OPT(CURLOPT_LOCALPORT, MIN(Z_LVAL_P(prs_cpy), Z_LVAL_P(pre_cpy)));
- PHP_HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, labs(Z_LVAL_P(prs_cpy)-Z_LVAL_P(pre_cpy))+1L);
- }
- zval_ptr_dtor(&prs_cpy);
- zval_ptr_dtor(&pre_cpy);
- }
- }
- }
- }
-
- /* another port */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("port"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_PORT, Z_LVAL_P(zoption));
- }
-
- /* RFC4007 zone_id */
-#if PHP_HTTP_CURL_VERSION(7,19,0)
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("address_scope"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_ADDRESS_SCOPE, Z_LVAL_P(zoption));
- }
-#endif
-
- /* auth */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("httpauth"), IS_STRING)) && Z_STRLEN_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_USERPWD, Z_STRVAL_P(zoption));
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("httpauthtype"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_HTTPAUTH, Z_LVAL_P(zoption));
- }
-
- /* redirects, defaults to 0 */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("redirect"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1L : 0L);
- PHP_HTTP_CURL_OPT(CURLOPT_MAXREDIRS, request->_cache.redirects = Z_LVAL_P(zoption));
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("unrestrictedauth"), IS_BOOL))) {
- PHP_HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("postredir"), IS_BOOL))) {
-#if PHP_HTTP_CURL_VERSION(7,19,1)
- PHP_HTTP_CURL_OPT(CURLOPT_POSTREDIR, Z_BVAL_P(zoption) ? 1L : 0L);
-#else
- PHP_HTTP_CURL_OPT(CURLOPT_POST301, Z_BVAL_P(zoption) ? 1L : 0L);
-#endif
- }
- } else {
- request->_cache.redirects = 0;
- }
-
- /* retries, defaults to 0 */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("retrycount"), IS_LONG))) {
- request->_retry.count = Z_LVAL_P(zoption);
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("retrydelay"), IS_DOUBLE))) {
- request->_retry.delay = Z_DVAL_P(zoption);
- } else {
- request->_retry.delay = 0;
- }
- } else {
- request->_retry.count = 0;
- }
-
- /* referer */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("referer"), IS_STRING)) && Z_STRLEN_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_REFERER, Z_STRVAL_P(zoption));
- }
-
- /* useragent, default "PECL::HTTP/version (PHP/version)" */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("useragent"), IS_STRING))) {
- /* allow to send no user agent, not even default one */
- if (Z_STRLEN_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_USERAGENT, Z_STRVAL_P(zoption));
- } else {
- PHP_HTTP_CURL_OPT(CURLOPT_USERAGENT, NULL);
- }
- }
-
- /* resume */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("resume"), IS_LONG)) && (Z_LVAL_P(zoption) > 0)) {
- range_req = 1;
- PHP_HTTP_CURL_OPT(CURLOPT_RESUME_FROM, Z_LVAL_P(zoption));
- }
- /* or range of kind array(array(0,499), array(100,1499)) */
- else if ((zoption = php_http_request_option(request, options, ZEND_STRS("range"), IS_ARRAY)) && zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
- HashPosition pos1, pos2;
- zval **rr, **rb, **re;
- php_http_buffer_t rs;
-
- php_http_buffer_init(&rs);
- FOREACH_VAL(pos1, zoption, rr) {
- if (Z_TYPE_PP(rr) == IS_ARRAY) {
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(rr), &pos2);
- if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &rb, &pos2)) {
- zend_hash_move_forward_ex(Z_ARRVAL_PP(rr), &pos2);
- if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &re, &pos2)) {
- if ( ((Z_TYPE_PP(rb) == IS_LONG) || ((Z_TYPE_PP(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(rb), Z_STRLEN_PP(rb), NULL, NULL, 1))) &&
- ((Z_TYPE_PP(re) == IS_LONG) || ((Z_TYPE_PP(re) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(re), Z_STRLEN_PP(re), NULL, NULL, 1)))) {
- zval *rbl = php_http_zsep(IS_LONG, *rb);
- zval *rel = php_http_zsep(IS_LONG, *re);
-
- if ((Z_LVAL_P(rbl) >= 0) && (Z_LVAL_P(rel) >= 0)) {
- php_http_buffer_appendf(&rs, "%ld-%ld,", Z_LVAL_P(rbl), Z_LVAL_P(rel));
- }
- zval_ptr_dtor(&rbl);
- zval_ptr_dtor(&rel);
- }
- }
- }
- }
- }
-
- if (PHP_HTTP_BUFFER_LEN(&rs)) {
- zval *cached_range;
-
- /* ditch last comma */
- PHP_HTTP_BUFFER_VAL(&rs)[PHP_HTTP_BUFFER_LEN(&rs)-- -1] = '\0';
- /* cache string */
- MAKE_STD_ZVAL(cached_range);
- ZVAL_STRINGL(cached_range, PHP_HTTP_BUFFER_VAL(&rs), PHP_HTTP_BUFFER_LEN(&rs), 0);
- PHP_HTTP_CURL_OPT(CURLOPT_RANGE, Z_STRVAL_P(php_http_request_option_cache(request, ZEND_STRS("range"), 0, cached_range)));
- zval_ptr_dtor(&cached_range);
- }
- }
-
- /* additional headers, array('name' => 'value') */
- if (request->_cache.headers) {
- curl_slist_free_all(request->_cache.headers);
- request->_cache.headers = NULL;
- }
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("headers"), IS_ARRAY))) {
- php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
- zval **header_val;
- HashPosition pos;
- php_http_buffer_t header;
-
- php_http_buffer_init(&header);
- FOREACH_KEYVAL(pos, zoption, header_key, header_val) {
- if (header_key.type == HASH_KEY_IS_STRING) {
- zval *header_cpy = php_http_zsep(IS_STRING, *header_val);
-
- if (!strcasecmp(header_key.str, "range")) {
- range_req = 1;
- }
-
- php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
- php_http_buffer_fix(&header);
- request->_cache.headers = curl_slist_append(request->_cache.headers, PHP_HTTP_BUFFER_VAL(&header));
- php_http_buffer_reset(&header);
-
- zval_ptr_dtor(&header_cpy);
- }
- }
- php_http_buffer_dtor(&header);
- }
- /* etag */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("etag"), IS_STRING)) && Z_STRLEN_P(zoption)) {
- zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"'));
- php_http_buffer_t header;
-
- php_http_buffer_init(&header);
- php_http_buffer_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", range_req?"If-Match":"If-None-Match", Z_STRVAL_P(zoption));
- php_http_buffer_fix(&header);
- request->_cache.headers = curl_slist_append(request->_cache.headers, PHP_HTTP_BUFFER_VAL(&header));
- php_http_buffer_dtor(&header);
- }
- /* compression */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("compress"), IS_BOOL)) && Z_LVAL_P(zoption)) {
- request->_cache.headers = curl_slist_append(request->_cache.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5");
- }
- PHP_HTTP_CURL_OPT(CURLOPT_HTTPHEADER, request->_cache.headers);
-
- /* lastmodified */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("lastmodified"), IS_LONG))) {
- if (Z_LVAL_P(zoption)) {
- if (Z_LVAL_P(zoption) > 0) {
- PHP_HTTP_CURL_OPT(CURLOPT_TIMEVALUE, Z_LVAL_P(zoption));
- } else {
- PHP_HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) PHP_HTTP_G->env.request.time + Z_LVAL_P(zoption));
- }
- PHP_HTTP_CURL_OPT(CURLOPT_TIMECONDITION, (long) (range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE));
- } else {
- PHP_HTTP_CURL_OPT(CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
- }
- }
-
- /* cookies, array('name' => 'value') */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("cookies"), IS_ARRAY))) {
- php_http_buffer_dtor(&request->_cache.cookies);
- if (zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
- zval *urlenc_cookies = NULL;
- /* check whether cookies should not be urlencoded; default is to urlencode them */
- if ((!(urlenc_cookies = php_http_request_option(request, options, ZEND_STRS("encodecookies"), IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
- if (SUCCESS == php_http_url_encode_hash_recursive(HASH_OF(zoption), &request->_cache.cookies, "; ", lenof("; "), NULL, 0 TSRMLS_CC)) {
- php_http_buffer_fix(&request->_cache.cookies);
- PHP_HTTP_CURL_OPT(CURLOPT_COOKIE, request->_cache.cookies.data);
- }
- } else {
- HashPosition pos;
- php_http_array_hashkey_t cookie_key = php_http_array_hashkey_init(0);
- zval **cookie_val;
-
- FOREACH_KEYVAL(pos, zoption, cookie_key, cookie_val) {
- if (cookie_key.type == HASH_KEY_IS_STRING) {
- zval *val = php_http_zsep(IS_STRING, *cookie_val);
- php_http_buffer_appendf(&request->_cache.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(val));
- zval_ptr_dtor(&val);
- }
- }
-
- php_http_buffer_fix(&request->_cache.cookies);
- if (PHP_HTTP_BUFFER_LEN(&request->_cache.cookies)) {
- PHP_HTTP_CURL_OPT(CURLOPT_COOKIE, PHP_HTTP_BUFFER_VAL(&request->_cache.cookies));
- }
- }
- }
- }
-
- /* don't load session cookies from cookiestore */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("cookiesession"), IS_BOOL)) && Z_BVAL_P(zoption)) {
- PHP_HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1L);
- }
-
- /* cookiestore, read initial cookies from that file and store cookies back into that file */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("cookiestore"), IS_STRING))) {
- if (Z_STRLEN_P(zoption)) {
- if (SUCCESS != php_check_open_basedir(Z_STRVAL_P(zoption) TSRMLS_CC)) {
- return FAILURE;
- }
- }
- if (storage->cookiestore) {
- pefree(storage->cookiestore, 1);
- }
- storage->cookiestore = pestrndup(Z_STRVAL_P(zoption), Z_STRLEN_P(zoption), 1);
- PHP_HTTP_CURL_OPT(CURLOPT_COOKIEFILE, storage->cookiestore);
- PHP_HTTP_CURL_OPT(CURLOPT_COOKIEJAR, storage->cookiestore);
- }
-
- /* maxfilesize */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("maxfilesize"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, Z_LVAL_P(zoption));
- }
-
- /* http protocol */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("protocol"), IS_LONG))) {
- PHP_HTTP_CURL_OPT(CURLOPT_HTTP_VERSION, Z_LVAL_P(zoption));
- }
-
- /* timeout, defaults to 0 */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("timeout"), IS_DOUBLE))) {
- PHP_HTTP_CURL_OPT(CURLOPT_TIMEOUT_MS, (long)(Z_DVAL_P(zoption)*1000));
- }
- /* connecttimeout, defaults to 0 */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("connecttimeout"), IS_DOUBLE))) {
- PHP_HTTP_CURL_OPT(CURLOPT_CONNECTTIMEOUT_MS, (long)(Z_DVAL_P(zoption)*1000));
- }
-
- /* ssl */
- if ((zoption = php_http_request_option(request, options, ZEND_STRS("ssl"), IS_ARRAY))) {
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **param;
- HashPosition pos;
-
- FOREACH_KEYVAL(pos, zoption, key, param) {
- if (key.type == HASH_KEY_IS_STRING) {
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLCERT, 0, 1);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLCERTTYPE, 0, 0);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLCERTPASSWD, 0, 0);
-
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLKEY, 0, 0);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLKEYTYPE, 0, 0);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLKEYPASSWD, 0, 0);
-
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLENGINE, 0, 0);
- PHP_HTTP_CURL_OPT_LONG(CURLOPT_SSLVERSION, 0);
-
- PHP_HTTP_CURL_OPT_LONG(CURLOPT_SSL_VERIFYPEER, 1);
- PHP_HTTP_CURL_OPT_LONG(CURLOPT_SSL_VERIFYHOST, 1);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSL_CIPHER_LIST, 1, 0);
-
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_CAINFO, -3, 1);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_CAPATH, -3, 1);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_RANDOM_FILE, -3, 1);
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_EGDSOCKET, -3, 1);
-#if PHP_HTTP_CURL_VERSION(7,19,0)
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_ISSUERCERT, -3, 1);
- #if defined(PHP_HTTP_HAVE_OPENSSL)
- PHP_HTTP_CURL_OPT_STRING(CURLOPT_CRLFILE, -3, 1);
- #endif
-#endif
-#if PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)
- PHP_HTTP_CURL_OPT_LONG(CURLOPT_CERTINFO, -3);
-#endif
- }
- }
- }
-
- /* request method */
- switch (request->meth) {
- case PHP_HTTP_GET:
- PHP_HTTP_CURL_OPT(CURLOPT_HTTPGET, 1L);
- break;
-
- case PHP_HTTP_HEAD:
- PHP_HTTP_CURL_OPT(CURLOPT_NOBODY, 1L);
- break;
-
- case PHP_HTTP_POST:
- PHP_HTTP_CURL_OPT(CURLOPT_POST, 1L);
- break;
-
- case PHP_HTTP_PUT:
- PHP_HTTP_CURL_OPT(CURLOPT_UPLOAD, 1L);
- break;
-
- default: {
- const char *meth = php_http_request_method_name(request->meth);
-
- if (meth) {
- PHP_HTTP_CURL_OPT(CURLOPT_CUSTOMREQUEST, meth);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", request->meth, request->url);
- return FAILURE;
- }
- break;
- }
- }
-
- /* attach request body */
- if (request->body && (request->meth != PHP_HTTP_GET) && (request->meth != PHP_HTTP_HEAD) && (request->meth != PHP_HTTP_OPTIONS)) {
- if (1 || request->meth == PHP_HTTP_PUT) {
- /* PUT/UPLOAD _needs_ READDATA */
- PHP_HTTP_CURL_OPT(CURLOPT_IOCTLDATA, request);
- PHP_HTTP_CURL_OPT(CURLOPT_READDATA, request);
- PHP_HTTP_CURL_OPT(CURLOPT_INFILESIZE, php_http_message_body_size(request->body));
- } else {
- abort();
- //PHP_HTTP_CURL_OPT(CURLOPT_POSTFIELDS, request->body->real->data);
- PHP_HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, php_http_message_body_size(request->body));
- }
- }
-
- return SUCCESS;
-}
-
-PHP_HTTP_API void php_http_request_exec(php_http_request_t *request)
-{
- uint tries = 0;
- CURLcode result;
- TSRMLS_FETCH_FROM_CTX(request->ts);
-
-retry:
- if (CURLE_OK != (result = curl_easy_perform(request->ch))) {
- php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST, "%s; %s (%s)", curl_easy_strerror(result), php_http_request_storage_get(request->ch)->errorbuffer, request->url);
- if (EG(exception)) {
- add_property_long(EG(exception), "curlCode", result);
- }
-
- if (request->_retry.count > tries++) {
- switch (result) {
- case CURLE_COULDNT_RESOLVE_PROXY:
- case CURLE_COULDNT_RESOLVE_HOST:
- case CURLE_COULDNT_CONNECT:
- case CURLE_WRITE_ERROR:
- case CURLE_READ_ERROR:
- case CURLE_OPERATION_TIMEDOUT:
- case CURLE_SSL_CONNECT_ERROR:
- case CURLE_GOT_NOTHING:
- case CURLE_SSL_ENGINE_SETFAILED:
- case CURLE_SEND_ERROR:
- case CURLE_RECV_ERROR:
- case CURLE_SSL_ENGINE_INITFAILED:
- case CURLE_LOGIN_DENIED:
- if (request->_retry.delay >= PHP_HTTP_DIFFSEC) {
- php_http_sleep(request->_retry.delay);
- }
- goto retry;
- default:
- break;
- }
- }