From: Michael Wallner Date: Thu, 6 Nov 2014 12:07:15 +0000 (+0100) Subject: Merge branch 'R_2_1' X-Git-Tag: RELEASE_2_2_0_RC1~9^2~3 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=4dde50dd5e77937157350e3aba617261e074bf92;hp=-c Merge branch 'R_2_1' --- 4dde50dd5e77937157350e3aba617261e074bf92 diff --combined php_http_client_curl.c index 1f0e1aa,4573df7..48bd0de --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@@ -282,7 -282,7 +282,7 @@@ static int php_http_curle_raw_callback( } else if (php_memnstr(data, ZEND_STRL("Operation timed out"), data + length)) { h->progress.info = "timeout"; } else { -#if PHP_DEBUG +#if 0 h->progress.info = data; data[length - 1] = '\0'; #endif @@@ -785,6 -785,8 +785,6 @@@ static void php_http_curlm_timer_callba if (!event_initialized(curl->timeout)) { event_assign(curl->timeout, curl->evbase, CURL_SOCKET_TIMEOUT, 0, php_http_curlm_timeout_callback, context); - } else if (event_pending(curl->timeout, EV_TIMEOUT, NULL)) { - event_del(curl->timeout); } timeout.tv_sec = timeout_ms / 1000; @@@ -905,7 -907,7 +905,7 @@@ static STATUS php_http_curle_option_set return FAILURE; } } else { - if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_TIMEVALUE, (long) PHP_HTTP_G->env.request.time + Z_LVAL_P(val))) { + if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_TIMEVALUE, (long) sapi_get_request_time(TSRMLS_C) + Z_LVAL_P(val))) { return FAILURE; } } @@@ -1634,15 -1636,25 +1634,25 @@@ static STATUS php_http_client_curl_hand php_http_message_update_headers(msg); if (zend_hash_num_elements(&msg->hdrs)) { php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0); - zval **header_val; + zval **header_val, *header_cpy; HashPosition pos; php_http_buffer_t header; + #if !PHP_HTTP_CURL_VERSION(7,23,0) + zval **ct = NULL; + + zend_hash_find(&msg->hdrs, ZEND_STRS("Content-Length"), (void *) &ct); + #endif php_http_buffer_init(&header); FOREACH_HASH_KEYVAL(pos, &msg->hdrs, header_key, header_val) { if (header_key.type == HASH_KEY_IS_STRING) { - zval *header_cpy = php_http_ztyp(IS_STRING, *header_val); - + #if !PHP_HTTP_CURL_VERSION(7,23,0) + /* avoid duplicate content-length header */ + if (ct && *ct == *header_val) { + continue; + } + #endif + header_cpy = php_http_ztyp(IS_STRING, *header_val); php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy)); php_http_buffer_fix(&header); curl->options.headers = curl_slist_append(curl->options.headers, header.data); @@@ -1882,17 -1894,6 +1892,17 @@@ static void php_http_client_curl_reset( } } +static inline void php_http_client_curl_get_timeout(php_http_client_curl_t *curl, long max_tout, struct timeval *timeout) +{ + if ((CURLM_OK == curl_multi_timeout(curl->handle, &max_tout)) && (max_tout > 0)) { + timeout->tv_sec = max_tout / 1000; + timeout->tv_usec = (max_tout % 1000) * 1000; + } else { + timeout->tv_sec = 0; + timeout->tv_usec = 1000; + } +} + #ifdef PHP_WIN32 # define SELECT_ERROR SOCKET_ERROR #else @@@ -1908,18 -1909,10 +1918,18 @@@ static STATUS php_http_client_curl_wait #if PHP_HTTP_HAVE_EVENT if (curl->useevents) { - TSRMLS_FETCH_FROM_CTX(h->ts); + if (!event_initialized(curl->timeout)) { + event_assign(curl->timeout, curl->evbase, CURL_SOCKET_TIMEOUT, 0, php_http_curlm_timeout_callback, h); + } else if (custom_timeout && timerisset(custom_timeout)) { + event_add(curl->timeout, custom_timeout); + } else if (!event_pending(curl->timeout, EV_TIMEOUT, NULL)) { + php_http_client_curl_get_timeout(curl, 1000, &timeout); + event_add(curl->timeout, &timeout); + } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "not implemented"); - return FAILURE; + event_base_loop(curl->evbase, EVLOOP_ONCE); + + return SUCCESS; } #endif @@@ -1931,7 -1924,15 +1941,7 @@@ if (custom_timeout && timerisset(custom_timeout)) { timeout = *custom_timeout; } else { - long max_tout = 1000; - - if ((CURLM_OK == curl_multi_timeout(curl->handle, &max_tout)) && (max_tout > 0)) { - timeout.tv_sec = max_tout / 1000; - timeout.tv_usec = (max_tout % 1000) * 1000; - } else { - timeout.tv_sec = 0; - timeout.tv_usec = 1000; - } + php_http_client_curl_get_timeout(curl, 1000, &timeout); } if (MAX == -1) { @@@ -1950,9 -1951,12 +1960,9 @@@ static int php_http_client_curl_once(ph #if PHP_HTTP_HAVE_EVENT if (curl->useevents) { - TSRMLS_FETCH_FROM_CTX(h->ts); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "not implemented"); - return FAILURE; - } + event_base_loop(curl->evbase, EVLOOP_NONBLOCK); + } else #endif - while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curl->handle, &curl->unfinished)); php_http_curlm_responsehandler(h);