Merge branch 'R_2_1'
authorMichael Wallner <mike@php.net>
Thu, 6 Nov 2014 12:07:15 +0000 (13:07 +0100)
committerMichael Wallner <mike@php.net>
Thu, 6 Nov 2014 12:07:15 +0000 (13:07 +0100)
1  2 
php_http_client_curl.c

diff --combined php_http_client_curl.c
index 1f0e1aa54c376be5a99ba8011eb9fe865b5d2d5f,4573df7e1ce7c1c76a1f04ce53b69f751898b3db..48bd0deb02789810778ef25840fc73aa1d6dcd8f
@@@ -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
  
                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);