curl interop
authorMichael Wallner <mike@php.net>
Tue, 7 Sep 2021 06:46:16 +0000 (08:46 +0200)
committerMichael Wallner <mike@php.net>
Tue, 7 Sep 2021 07:30:08 +0000 (09:30 +0200)
autoconf/pecl/libbrotli.m4
autoconf/pecl/libcurl.m4
autoconf/pecl/pecl.m4
config9.m4
src/php_http_client_curl.c
tests/client002.phpt
tests/client021.phpt
tests/client027.phpt
tests/client031.phpt
tests/client032.phpt
tests/helper/dump.inc

index f8916e2d79cb99fc0e67accb35f9882e0195141e..575f635111c0fc813a91d6bf7264e4ba760538e5 100644 (file)
@@ -1,5 +1,11 @@
 
 AC_DEFUN([PECL_CHECK_LIBBROTLI], [
+       dnl config.m4 calls PECL_CHECK_DONE once more
+       PECL_COUNT_CHECKS([+1])
+       PECL_SAVE_ENV([CPPFLAGS], [libbrotli])
+       PECL_SAVE_ENV([LDFLAGS], [libbrotli])
+       PECL_SAVE_ENV([LIBS], [libbrotli])
+
        PECL_CHECK_LIBBROTLI_COMMON([$1], [$2])
        PECL_CHECK_DONE(libbrotlicommon, [$PECL_VAR([HAVE_LIBBROTLI_COMMON])])
        PECL_CHECK_LIBBROTLI_DEC([$1], [$2])
index 4d9920741f7ec73285d39d900813f0c9a22182da..8de9499e0eaef8351c9a397a1a9e2051f66ee008 100644 (file)
@@ -160,6 +160,48 @@ AC_DEFUN([PECL_HAVE_LIBCURL_SSL], [dnl
                                fi
                        fi
                ])
+
+               PECL_HAVE_CONST([curl/curl.h], [CURL_LOCK_DATA_SSL_SESSION], int, [
+                       AC_CACHE_CHECK([whether curl_share accepts CURL_LOCK_DATA_SSL_SESSION], PECL_CACHE_VAR([LIBCURL_SHARE_SSL]), [
+                               PECL_CACHE_VAR([LIBCURL_SHARE_SSL])=
+                               AC_TRY_RUN([
+                                       #include <curl/curl.h>
+                                       int main(int argc, char *argv[]) {
+                                               CURLSH *ch = curl_share_init();
+                                               return curl_share_setopt(ch, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
+                                       }
+                               ], [
+                                       PECL_CACHE_VAR([LIBCURL_SHARE_SSL])=yes
+                               ], [
+                                       PECL_CACHE_VAR([LIBCURL_SHARE_SSL])=no
+                               ])
+                       ])
+                       if test "$PECL_CACHE_VAR([LIBCURL_SHARE_SSL])" = yes; then
+                               PECL_DEFINE([HAVE_LIBCURL_SHARE_SSL], [1])
+                       fi
+               ])
+
+               if test "$PECL_VAR([LIBCURL_SSLLIB])" == "OpenSSL"; then
+                       PECL_HAVE_CONST([curl/curl.h], [CURLOPT_TLS13_CIPHERS], int, [
+                               AC_CACHE_CHECK([whether curl_easy_setopt accepts CURLOPT_TLS13_CIPHERS], PECL_CACHE_VAR([LIBCURL_TLS13_CIPHERS]), [
+                                       PECL_CACHE_VAR([LIBCURL_TLS13_CIPHERS])=
+                                       AC_TRY_RUN([
+                                               #include <curl/curl.h>
+                                               int main(int argc, char *argv[]) {
+                                                       CURL *ch = curl_easy_init();
+                                                       return curl_easy_setopt(ch, CURLSHOPT_TLS13_CIPHERS, "");
+                                               }
+                                       ], [
+                                               PECL_CACHE_VAR([LIBCURL_TLS13_CIPHERS])=yes
+                                       ], [
+                                               PECL_CACHE_VAR([LIBCURL_TLS13_CIPHERS])=no
+                                       ])
+                               ])
+                               if test "$PECL_CACHE_VAR([LIBCURL_TLS13_CIPHERS])" = yes; then
+                                       PECL_DEFINE([HAVE_LIBCURL_TLS13_CIPHERS], [1])
+                               fi
+                       ])
+               fi
        ])
 ])
 dnl
index ffa45ac03fe88cf746f84378199040747f242ce6..d8735b0326628c8baf76dc78bf2e9c99065d8eab 100644 (file)
@@ -70,6 +70,12 @@ AC_DEFUN([PECL_RESTORE_ENV], [
        $1=$PECL_SAVE_VAR([$2_$1])
 ])
 dnl
+dnl PECL_COUNT_CHECKS(incdec)
+dnl
+AC_DEFUN([PECL_COUNT_CHECKS], [
+       PECL_VAR([_checks])=$(($PECL_VAR([_checks])$1))
+])
+dnl
 dnl PECL_EVAL_LIBLINE(libline)
 dnl
 AC_DEFUN([PECL_EVAL_LIBLINE], [
@@ -244,6 +250,7 @@ dnl
 dnl PECL_CHECK_CUSTOM(name, path, header, lib, version)
 dnl
 AC_DEFUN([PECL_CHECK_CUSTOM], [
+       PECL_COUNT_CHECKS([+1])
        PECL_SAVE_ENV([CPPFLAGS], [$1])
        PECL_SAVE_ENV([LDFLAGS], [$1])
        PECL_SAVE_ENV([LIBS], [$1])
@@ -260,10 +267,10 @@ AC_DEFUN([PECL_CHECK_CUSTOM], [
                done
        ])
        if test -n "$PECL_CACHE_VAR([$1_prefix])"; then
-               CPPFLAGS="-I$PECL_CACHE_VAR([$1_prefix])/include"
-               LDFLAGS="-L$PECL_CACHE_VAR([$1_prefix])/$PHP_LIBDIR"
-               LIBS="-l$4"
-               PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
+               CPPFLAGS="$CPPFLAGS -I$PECL_CACHE_VAR([$1_prefix])/include"
+               LDFLAGS="$LDFLAGS -L$PECL_CACHE_VAR([$1_prefix])/$PHP_LIBDIR"
+               LIBS="$LIBS -l$4"
+               dnl PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
                
                AC_CACHE_VAL(PECL_CACHE_VAR([$1_version]), [
                        pushd $PECL_CACHE_VAR([$1_prefix]) >/dev/null
@@ -288,11 +295,11 @@ dnl
 dnl PECL_CHECK_CONFIG(name, prog-config, version-flag, cppflags-flag, ldflags-flag, libs-flag)
 dnl
 AC_DEFUN([PECL_CHECK_CONFIG], [
+       PECL_COUNT_CHECKS([+1])
        PECL_SAVE_ENV([CPPFLAGS], [$1])
        PECL_SAVE_ENV([LDFLAGS], [$1])
        PECL_SAVE_ENV([LIBS], [$1])
 
-
        AC_MSG_CHECKING([for $1])
        ifelse($2, [$PKG_CONFIG $1], [
                AC_CACHE_VAL(PECL_CACHE_VAR([$1_exists]), [
@@ -311,20 +318,22 @@ AC_DEFUN([PECL_CHECK_CONFIG], [
                AC_CACHE_VAL(PECL_CACHE_VAR([$1_cppflags]), [
                        PECL_CACHE_VAR([$1_cppflags])=$($2 $4)
                ])
-               CPPFLAGS=$PECL_CACHE_VAR([$1_cppflags])
+               CPPFLAGS="$CPPFLAGS $PECL_CACHE_VAR([$1_cppflags])"
                AC_CACHE_VAL(PECL_CACHE_VAR([$1_ldflags]), [
                        PECL_CACHE_VAR([$1_ldflags])=$($2 $5)
                ])
-               LDFLAGS=$PECL_CACHE_VAR([$1_ldflags])
+               LDFLAGS="$LDFLAGS $PECL_CACHE_VAR([$1_ldflags])"
                AC_CACHE_VAL(PECL_CACHE_VAR([$1_libs]), [
                        PECL_CACHE_VAR([$1_libs])=$($2 $6)
                ])
-               LIBS=$PECL_CACHE_VAR([$1_libs])
-               PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
+               LIBS="$LIBS $PECL_CACHE_VAR([$1_libs])"
+               dnl PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
        ifelse($2, [$PKG_CONFIG $1], [
                fi
        ])
 
+       AC_MSG_RESULT([${PECL_CHECKED_VERSION([$1]):-no}])
+
        if test -n "$PECL_CHECKED_VERSION([$1])"; then
                PECL_VAR([HAVE_$1])=true
                PECL_DEFINE([HAVE_$1])
@@ -332,8 +341,6 @@ AC_DEFUN([PECL_CHECK_CONFIG], [
        else
                PECL_VAR([HAVE_$1])=false
        fi
-
-       AC_MSG_RESULT([${PECL_CHECKED_VERSION([$1]):-no}])
 ])
 dnl
 dnl PECL_CHECK_PKGCONFIG(pkg[, additional-pkg-config-path])
@@ -355,9 +362,25 @@ dnl
 dnl PECL_CHECK_DONE(name, success[, incline, libline])
 dnl
 AC_DEFUN([PECL_CHECK_DONE], [
-       if $2; then
-               incline=$CPPFLAGS
-               libline="$LDFLAGS $LIBS"
+       PECL_COUNT_CHECKS([-1])
+       success=$2
+       if $success && test -n "$LDFLAGS$LIBS"; then
+               AC_MSG_CHECKING([whether $1 can be linked])
+               AC_TRY_LINK([], [], [success=yes], [success=no])
+               AC_MSG_RESULT([$success])
+               if ! $success; then
+                       AC_MSG_WARN([$1 was found, but fails to link with:])
+                       AC_MSG_WARN([    LDFLAGS='$LDFLAGS'])
+                       AC_MSG_WARN([    LIBS='$LIBS'])
+                       AC_MSG_WARN([Missing or updated library paths?])
+               fi
+       fi
+       if $success; then
+               _cppflags=$PECL_SAVE_VAR([$1_CPPFLAGS])
+               _ldflags=$PECL_SAVE_VAR([$1_LDFLAGS])
+               _libs=$PECL_SAVE_VAR([$1_LIBS])
+               incline=${CPPFLAGS:${#_cppflags}}
+               libline=["${LDFLAGS:${#_ldflags}} ${LIBS:${#_libs}}"]
                PECL_DEFINE([HAVE_$1])
        else
                incline=$3
index ef7d33eabedef510e0d9c1f692f2af7869bfc73a..695701b6362ec620a970528b0d315ba3109d7fbf 100644 (file)
@@ -24,6 +24,8 @@ if test "$PHP_HTTP" != "no"; then
                AC_CHECK_LIB(nsl, getdomainname)
        ])
        AC_CHECK_FUNCS(mbrtowc mbtowc iswalnum inet_pton)
+       
+       CFLAGS="$CFLAGS -Wno-strict-prototypes"
 
        dnl ZLIB
        PHP_ARG_WITH([http-zlib-dir], [whether/where to check for zlib],
index 0e79f197bd3255cda32398ea4ab0843f55811480..8898b5dda91ec37b0ea8f5c73c8085809342e733 100644 (file)
@@ -17,6 +17,8 @@
 
 #if PHP_HTTP_HAVE_LIBCURL
 
+#define DEBUG_COOKIES 0
+
 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
 #      include <openssl/ssl.h>
 #endif
@@ -834,6 +836,9 @@ static ZEND_RESULT_CODE php_http_curle_option_set_cookiesession(php_http_option_
                return FAILURE;
        }
        if (Z_TYPE_P(val) == IS_TRUE) {
+#if DEBUG_COOKIES
+               fprintf(stderr, "CURLOPT_COOKIELIST: SESS\n");
+#endif
                if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIELIST, "SESS")) {
                        return FAILURE;
                }
@@ -856,9 +861,19 @@ static ZEND_RESULT_CODE php_http_curle_option_set_cookiestore(php_http_option_t
        } else {
                storage->cookiestore = NULL;
        }
-       if (    CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEFILE, storage->cookiestore ? storage->cookiestore : "")
-               ||      CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEJAR, storage->cookiestore)
-       ) {
+
+#if DEBUG_COOKIES
+       fprintf(stderr, "CURLOPT_COOKIEFILE: %s\n", cookiestore);
+#endif
+       // does NOT enable ch->data.cookies until transfer; adds to ch->stsate.cookielist
+       if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEFILE, storage->cookiestore ? storage->cookiestore : "")) {
+               return FAILURE;
+       }
+#if DEBUG_COOKIES
+       fprintf(stderr, "CURLOPT_COOKIEJAR: %s\n", cookiestore);
+#endif
+       // enables ch->data.cookies
+       if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEJAR, storage->cookiestore)) {
                return FAILURE;
        }
 
@@ -1587,7 +1602,7 @@ static void php_http_curle_options_init(php_http_options_t *registry)
                                opt->flags |= PHP_HTTP_CURLE_OPTION_IGNORE_RC;
                        }
 #endif
-#if PHP_HTTP_CURL_VERSION(7,61,0)
+#if PHP_HTTP_CURL_VERSION(7,61,0) && PHP_HTTP_HAVE_LIBCURL_TLS13_CIPHERS
                        if ((opt = php_http_option_register(ssl_registry, ZEND_STRL("tls13_ciphers"), CURLOPT_TLS13_CIPHERS, IS_STRING))) {
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
                        }
@@ -1676,7 +1691,7 @@ static void php_http_curle_options_init(php_http_options_t *registry)
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
                        }
 # endif
-# if PHP_HTTP_CURL_VERSION(7,61,0)
+# if PHP_HTTP_CURL_VERSION(7,61,0) && PHP_HTTP_HAVE_LIBCURL_TLS13_CIPHERS
                        if ((opt = php_http_option_register(proxy_registry, ZEND_STRL("tls13_ciphers"), CURLOPT_PROXY_TLS13_CIPHERS, IS_STRING))) {
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
                        }
@@ -1919,7 +1934,7 @@ static ZEND_RESULT_CODE php_http_curlm_option_set_share_cookies(php_http_option_
        return SUCCESS;
 }
 
-#if PHP_HTTP_CURL_VERSION(7,23,0)
+#if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
 static ZEND_RESULT_CODE php_http_curlm_option_set_share_ssl(php_http_option_t *opt, zval *value, void *userdata)
 {
        php_http_client_t *client = userdata;
@@ -1994,7 +2009,7 @@ static void php_http_curlm_options_init(php_http_options_t *registry)
                opt->setter = php_http_curlm_option_set_share_cookies;
                ZVAL_TRUE(&opt->defval);
        }
-#if PHP_HTTP_CURL_VERSION(7,23,0)
+#if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
        if ((opt = php_http_option_register(registry, ZEND_STRL("share_ssl"), 0, _IS_BOOL))) {
                opt->setter = php_http_curlm_option_set_share_ssl;
                ZVAL_TRUE(&opt->defval);
@@ -2052,9 +2067,10 @@ static ZEND_RESULT_CODE php_http_curlm_set_option(php_http_option_t *opt, zval *
 
 /* client ops */
 
-static ZEND_RESULT_CODE php_http_client_curl_handler_reset(php_http_client_curl_handler_t *curl)
+static ZEND_RESULT_CODE php_http_client_curl_handler_reset(php_http_client_curl_handler_t *handler)
 {
-       CURL *ch = curl->handle;
+       php_http_client_curl_t *curl = handler->client->ctx;
+       CURL *ch = handler->handle;
        php_http_curle_storage_t *st;
 
        if ((st = php_http_curle_get_storage(ch))) {
@@ -2083,27 +2099,55 @@ static ZEND_RESULT_CODE php_http_client_curl_handler_reset(php_http_client_curl_
 #endif
 
 #if PHP_HTTP_CURL_VERSION(7,21,3)
-       if (curl->options.resolve) {
-               curl_slist_free_all(curl->options.resolve);
-               curl->options.resolve = NULL;
+       if (handler->options.resolve) {
+               curl_slist_free_all(handler->options.resolve);
+               handler->options.resolve = NULL;
        }
 #endif
-       curl->options.retry.count = 0;
-       curl->options.retry.delay = 0;
-       curl->options.redirects = 0;
-       curl->options.encode_cookies = 1;
+       handler->options.retry.count = 0;
+       handler->options.retry.delay = 0;
+       handler->options.redirects = 0;
+       handler->options.encode_cookies = 1;
 
-       if (curl->options.headers) {
-               curl_slist_free_all(curl->options.headers);
-               curl->options.headers = NULL;
+       if (handler->options.headers) {
+               curl_slist_free_all(handler->options.headers);
+               handler->options.headers = NULL;
        }
-       if (curl->options.proxyheaders) {
-               curl_slist_free_all(curl->options.proxyheaders);
-               curl->options.proxyheaders = NULL;
+       if (handler->options.proxyheaders) {
+               curl_slist_free_all(handler->options.proxyheaders);
+               handler->options.proxyheaders = NULL;
        }
 
-       php_http_buffer_reset(&curl->options.cookies);
-       php_http_buffer_reset(&curl->options.ranges);
+       php_http_buffer_reset(&handler->options.cookies);
+       php_http_buffer_reset(&handler->options.ranges);
+
+#if ZTS
+       curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L);
+#endif
+       curl_easy_setopt(ch, CURLOPT_HEADER, 0L);
+       curl_easy_setopt(ch, CURLOPT_FILETIME, 1L);
+       curl_easy_setopt(ch, CURLOPT_AUTOREFERER, 1L);
+       curl_easy_setopt(ch, CURLOPT_VERBOSE, 1L);
+       curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 0L);
+       curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, php_http_curle_header_callback);
+       curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, php_http_curle_body_callback);
+       curl_easy_setopt(ch, CURLOPT_DEBUGFUNCTION, php_http_curle_raw_callback);
+       curl_easy_setopt(ch, CURLOPT_READFUNCTION, php_http_curle_read_callback);
+       curl_easy_setopt(ch, CURLOPT_SEEKFUNCTION, php_http_curle_seek_callback);
+#if PHP_HTTP_CURL_VERSION(7,32,0)
+       curl_easy_setopt(ch, CURLOPT_XFERINFOFUNCTION, php_http_curle_xferinfo_callback);
+       curl_easy_setopt(ch, CURLOPT_XFERINFODATA, handler);
+#else
+       curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, php_http_curle_progress_callback);
+       curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, handler);
+#endif
+       curl_easy_setopt(ch, CURLOPT_DEBUGDATA, handler);
+       curl_easy_setopt(ch, CURLOPT_WRITEDATA, handler);
+       curl_easy_setopt(ch, CURLOPT_HEADERDATA, handler);
+#if DEBUG_COOKIES
+       fprintf(stderr, "CURLOPT_SHARE: %p\n", curl->handle->share);
+#endif
+       curl_easy_setopt(ch, CURLOPT_SHARE, curl->handle->share);
 
        return SUCCESS;
 }
@@ -2111,7 +2155,6 @@ static ZEND_RESULT_CODE php_http_client_curl_handler_reset(php_http_client_curl_
 static php_http_client_curl_handler_t *php_http_client_curl_handler_init(php_http_client_t *h, php_resource_factory_t *rf)
 {
        void *handle;
-       php_http_client_curl_t *curl = h->ctx;
        php_http_client_curl_handler_t *handler;
 
        if (!(handle = php_resource_factory_handle_ctor(rf, NULL))) {
@@ -2129,31 +2172,6 @@ static php_http_client_curl_handler_t *php_http_client_curl_handler_init(php_htt
        php_http_buffer_init(&handler->options.ranges);
        zend_hash_init(&handler->options.cache, 0, NULL, ZVAL_PTR_DTOR, 0);
 
-#if ZTS
-       curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
-#endif
-       curl_easy_setopt(handle, CURLOPT_HEADER, 0L);
-       curl_easy_setopt(handle, CURLOPT_FILETIME, 1L);
-       curl_easy_setopt(handle, CURLOPT_AUTOREFERER, 1L);
-       curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
-       curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
-       curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, php_http_curle_header_callback);
-       curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, php_http_curle_body_callback);
-       curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, php_http_curle_raw_callback);
-       curl_easy_setopt(handle, CURLOPT_READFUNCTION, php_http_curle_read_callback);
-       curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, php_http_curle_seek_callback);
-#if PHP_HTTP_CURL_VERSION(7,32,0)
-       curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, php_http_curle_xferinfo_callback);
-       curl_easy_setopt(handle, CURLOPT_XFERINFODATA, handler);
-#else
-       curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, php_http_curle_progress_callback);
-       curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, handler);
-#endif
-       curl_easy_setopt(handle, CURLOPT_DEBUGDATA, handler);
-       curl_easy_setopt(handle, CURLOPT_WRITEDATA, handler);
-       curl_easy_setopt(handle, CURLOPT_HEADERDATA, handler);
-       curl_easy_setopt(handle, CURLOPT_SHARE, curl->handle->share);
-
        php_http_client_curl_handler_reset(handler);
 
        return handler;
@@ -2277,12 +2295,19 @@ static void php_http_client_curl_handler_clear(php_http_client_curl_handler_t *h
 #endif
        curl_easy_setopt(handler->handle, CURLOPT_VERBOSE, 0L);
        curl_easy_setopt(handler->handle, CURLOPT_DEBUGFUNCTION, NULL);
-       curl_easy_setopt(handler->handle, CURLOPT_COOKIELIST, "FLUSH");
-       curl_easy_setopt(handler->handle, CURLOPT_SHARE, NULL);
        /* see gh issue #84 */
 #if PHP_HTTP_CURL_VERSION(7,63,0) && !PHP_HTTP_CURL_VERSION(7,65,0)
-       curl_easy_setopt(handler->handle, CURLOPT_COOKIEJAR, NULL);
+       {
+               php_http_curle_storage_t *st = php_http_curle_get_storage(handler->handle);
+               curl_easy_setopt(handler->handle, CURLOPT_COOKIEJAR, st ? st->cookiestore : NULL);
+       }
+#endif
+#if DEBUG_COOKIES
+       fprintf(stderr, "CURLOPT_COOKIELIST: FLUSH\n");
+       fprintf(stderr, "CURLOPT_SHARE: (null)\n");
 #endif
+       curl_easy_setopt(handler->handle, CURLOPT_COOKIELIST, "FLUSH");
+       curl_easy_setopt(handler->handle, CURLOPT_SHARE, NULL);
 }
 
 static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t *handler)
index 0da72d00ba9f0d2b2c683898314d61e03a746799..d020f16e22ff4d5916b2ba4830ae1083c48c321a 100644 (file)
@@ -17,8 +17,10 @@ class Observer implements SplObserver
        #[ReturnTypeWillChange]
        function update(SplSubject $client, http\Client\Request $request = null, StdClass $progress = null) {
                echo "P";
-               if ($progress->info !== "prepare" && $client->getProgressInfo($request) != $progress) {
-                       var_dump($progress);
+               /* fence against buggy infof() calls in some curl versions */
+               $compare = $client->getProgressInfo($request);
+               if ($progress->info !== "prepare" && $compare && $compare != $progress) {
+                       var_dump($progress, $compare);
                }
        }
 }
index 702685dd125f6efb8c30b976d9f2c9a4d1271195..aaf462556b6f02aaf5176ac181c65dfd629c245d 100644 (file)
@@ -4,6 +4,9 @@ client cookies
 <?php
 include "skipif.inc";
 skip_client_test();
+if (0 === strpos(http\Client\Curl\Versions\CURL, "7.64.0")) {
+       die("skip - cookie handling broken or crashes with libcurl-7.64\n");
+}
 ?>
 --FILE--
 <?php
index d33a58db02c84dbb42b4d39dc6bc77d397957f00..19c7bd4ff12e8ca0057f52f0756716f02d8fe73f 100644 (file)
@@ -15,20 +15,21 @@ echo "Test\n";
 
 server("cookie.inc", function($port) {
        $client = new http\Client(null, "cookies");
-       $client->configure(array("pipelining" => false));
+       $client->configure(array("pipelining" => false, "share_cookies" => false));
+
        $request = new http\Client\Request("GET", "http://localhost:$port?r1");
        $client->enqueue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
+       dump_responses($client, ["counter" => 1]);
+
        $client->requeue($request);
+       $client->send();
+       dump_responses($client, ["counter" => 2]);
+
        $request = new http\Client\Request("GET", "http://localhost:$port?r2");
        $client->enqueue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
+       dump_responses($client, ["counter" => 1]);
 });
 
 ?>
@@ -44,7 +45,7 @@ Set-Cookie: counter=2;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
-Set-Cookie: counter=2;
+Set-Cookie: counter=1;
 X-Original-Transfer-Encoding: chunked
 
 ===DONE===
index 32117356b62190f080ad817b00cbc613d7bd9309..73ce7e4c6251cb5ae5147d5b422cfeab1c0c7a66 100644 (file)
@@ -16,32 +16,29 @@ echo "Test\n";
 server("cookie.inc", function($port) {
        $client = new http\Client(null, "cookies");
        $client->configure(array("share_cookies" => false));
+
        $request = new http\Client\Request("GET", "http://localhost:$port");
        $client->enqueue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
+       dump_responses($client, ["counter" => 1]);
+
        /* requeue the previous request */
        $client->requeue($request);
-       $request = new http\Client\Request("GET", "http://localhost:$port");
-       $client->enqueue($request);
-       $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
-       $request = new http\Client\Request("GET", "http://localhost:$port");
-       $client->enqueue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
+       dump_responses($client, ["counter" => 2]);
+
+       for($i = 0; $i < 3; ++$i) {
+               /* new requests */
+               $request = new http\Client\Request("GET", "http://localhost:$port");
+               $client->enqueue($request);
+               $client->send();
+               dump_responses($client, ["counter" => 1]);
        }
-       $request = new http\Client\Request("GET", "http://localhost:$port");
-       $client->enqueue($request);
+
+       /* requeue the previous request */
+       $client->requeue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
+       dump_responses($client, ["counter" => 2]);
 });
 
 ?>
@@ -53,11 +50,11 @@ Set-Cookie: counter=1;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
-Set-Cookie: counter=1;
+Set-Cookie: counter=2;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
-Set-Cookie: counter=2;
+Set-Cookie: counter=1;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
@@ -68,4 +65,8 @@ Etag: ""
 Set-Cookie: counter=1;
 X-Original-Transfer-Encoding: chunked
 
+Etag: ""
+Set-Cookie: counter=2;
+X-Original-Transfer-Encoding: chunked
+
 ===DONE===
index d8dfb2bb3a6dd94d8461d6c4d0a77c1708ccb542..954a68e2609018c7b63b7e813161a97fc9d4cd5a 100644 (file)
@@ -16,32 +16,29 @@ echo "Test\n";
 server("cookie.inc", function($port) {
        $client = new http\Client(null, "cookies");
        $client->configure(array("share_cookies" => true));
+
        $request = new http\Client\Request("GET", "http://localhost:$port");
        $client->enqueue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
+       dump_responses($client, ["counter" => 1]);
+
        /* requeue the previous request */
        $client->requeue($request);
-       $request = new http\Client\Request("GET", "http://localhost:$port");
-       $client->enqueue($request);
-       $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
-       $request = new http\Client\Request("GET", "http://localhost:$port");
-       $client->enqueue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
+       dump_responses($client, ["counter" => 2]);
+
+       for($i = 3; $i < 6; ++$i) {
+               /* new requests */
+               $request = new http\Client\Request("GET", "http://localhost:$port");
+               $client->enqueue($request);
+               $client->send();
+               dump_responses($client, ["counter" => $i]);
        }
-       $request = new http\Client\Request("GET", "http://localhost:$port");
-       $client->enqueue($request);
+
+       /* requeue the previous request */
+       $client->requeue($request);
        $client->send();
-       while (($r = $client->getResponse())) {
-               dump_headers(null, $r->getHeaders());
-       }
+       dump_responses($client, ["counter" => $i]);
 });
 
 ?>
@@ -57,15 +54,19 @@ Set-Cookie: counter=2;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
-Set-Cookie: counter=2;
+Set-Cookie: counter=3;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
-Set-Cookie: counter=3;
+Set-Cookie: counter=4;
 X-Original-Transfer-Encoding: chunked
 
 Etag: ""
-Set-Cookie: counter=4;
+Set-Cookie: counter=5;
+X-Original-Transfer-Encoding: chunked
+
+Etag: ""
+Set-Cookie: counter=6;
 X-Original-Transfer-Encoding: chunked
 
 ===DONE===
index 452a715e2dfa51042ba9c9ee0a7c9797f862180d..5612d06e606eca70e860e9d168ee1c55cff06f07 100644 (file)
@@ -24,4 +24,17 @@ function dump_message($stream, http\Message $msg, $parent = false) {
        }
 }
 
-?>
\ No newline at end of file
+function dump_responses($client, array $expect_cookie = []) {
+       while (($r = $client->getResponse())) {
+               dump_headers(null, $r->getHeaders());
+               if ($expect_cookie) {
+                       $got_cookies = array_merge(...array_map(fn($c) => $c->getCookies(), $r->getCookies()));
+                       if ($expect_cookie != $got_cookies) {
+                               var_dump($expect_cookie, $got_cookies);
+                               echo $r->toString(true);
+                       }
+               }
+       }
+
+}
+?>