From ef9c474299e45b4d952b6a821b11f5121624a5fc Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 7 Sep 2021 08:46:16 +0200 Subject: [PATCH] curl interop --- autoconf/pecl/libbrotli.m4 | 6 ++ autoconf/pecl/libcurl.m4 | 42 ++++++++++++ autoconf/pecl/pecl.m4 | 51 +++++++++++---- config9.m4 | 2 + src/php_http_client_curl.c | 131 ++++++++++++++++++++++--------------- tests/client002.phpt | 6 +- tests/client021.phpt | 3 + tests/client027.phpt | 17 ++--- tests/client031.phpt | 41 ++++++------ tests/client032.phpt | 43 ++++++------ tests/helper/dump.inc | 15 ++++- 11 files changed, 238 insertions(+), 119 deletions(-) diff --git a/autoconf/pecl/libbrotli.m4 b/autoconf/pecl/libbrotli.m4 index f8916e2..575f635 100644 --- a/autoconf/pecl/libbrotli.m4 +++ b/autoconf/pecl/libbrotli.m4 @@ -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]) diff --git a/autoconf/pecl/libcurl.m4 b/autoconf/pecl/libcurl.m4 index 4d99207..8de9499 100644 --- a/autoconf/pecl/libcurl.m4 +++ b/autoconf/pecl/libcurl.m4 @@ -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 + 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 + 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 diff --git a/autoconf/pecl/pecl.m4 b/autoconf/pecl/pecl.m4 index ffa45ac..d8735b0 100644 --- a/autoconf/pecl/pecl.m4 +++ b/autoconf/pecl/pecl.m4 @@ -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 diff --git a/config9.m4 b/config9.m4 index ef7d33e..695701b 100644 --- a/config9.m4 +++ b/config9.m4 @@ -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], diff --git a/src/php_http_client_curl.c b/src/php_http_client_curl.c index 0e79f19..8898b5d 100644 --- a/src/php_http_client_curl.c +++ b/src/php_http_client_curl.c @@ -17,6 +17,8 @@ #if PHP_HTTP_HAVE_LIBCURL +#define DEBUG_COOKIES 0 + #if PHP_HTTP_HAVE_LIBCURL_OPENSSL # include #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) diff --git a/tests/client002.phpt b/tests/client002.phpt index 0da72d0..d020f16 100644 --- a/tests/client002.phpt +++ b/tests/client002.phpt @@ -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); } } } diff --git a/tests/client021.phpt b/tests/client021.phpt index 702685d..aaf4625 100644 --- a/tests/client021.phpt +++ b/tests/client021.phpt @@ -4,6 +4,9 @@ client cookies --FILE-- 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=== diff --git a/tests/client031.phpt b/tests/client031.phpt index 3211735..73ce7e4 100644 --- a/tests/client031.phpt +++ b/tests/client031.phpt @@ -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=== diff --git a/tests/client032.phpt b/tests/client032.phpt index d8dfb2b..954a68e 100644 --- a/tests/client032.phpt +++ b/tests/client032.phpt @@ -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=== diff --git a/tests/helper/dump.inc b/tests/helper/dump.inc index 452a715..5612d06 100644 --- a/tests/helper/dump.inc +++ b/tests/helper/dump.inc @@ -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); + } + } + } + +} +?> -- 2.30.2