├── .codecov.yml ├── .coverity.asc ├── .editorconfig ├── .gitattributes ├── .github ├── Makefile └── workflows │ ├── ci.yml │ └── curl-matrix.yml ├── .gitignore ├── .gitmodules ├── AUTHORS ├── BUGS ├── CHANGELOG.md ├── CONTRIBUTING.md ├── CREDITS ├── CVE.md ├── LICENSE ├── Makefile.frag ├── README.md ├── THANKS ├── TODO ├── autoconf └── pecl │ ├── libbrotli.m4 │ ├── libcurl.m4 │ ├── libevent.m4 │ ├── pecl.m4 │ └── zlib.m4 ├── config.m4 ├── config.w32 ├── config9.m4 ├── package.xml ├── php_http.h ├── scripts ├── bench_select_vs_event.php ├── check_package-xml.php ├── coverity.sh ├── curlver.dist ├── gen_curlinfo.php ├── gen_github_workflow_ci.php ├── gen_github_workflow_curl-matrix.php ├── gen_if_utf8.php ├── gen_stubs.php ├── gen_switch_utf8.php └── gen_utf8.php ├── src ├── php_http.c ├── php_http_api.h ├── php_http_buffer.c ├── php_http_buffer.h ├── php_http_client.c ├── php_http_client.h ├── php_http_client_curl.c ├── php_http_client_curl.h ├── php_http_client_curl_event.c ├── php_http_client_curl_event.h ├── php_http_client_curl_user.c ├── php_http_client_curl_user.h ├── php_http_client_request.c ├── php_http_client_request.h ├── php_http_client_response.c ├── php_http_client_response.h ├── php_http_cookie.c ├── php_http_cookie.h ├── php_http_curl.c ├── php_http_curl.h ├── php_http_encoding.c ├── php_http_encoding.h ├── php_http_encoding_brotli.c ├── php_http_encoding_brotli.h ├── php_http_encoding_zlib.c ├── php_http_encoding_zlib.h ├── php_http_env.c ├── php_http_env.h ├── php_http_env_request.c ├── php_http_env_request.h ├── php_http_env_response.c ├── php_http_env_response.h ├── php_http_etag.c ├── php_http_etag.h ├── php_http_exception.c ├── php_http_exception.h ├── php_http_filter.c ├── php_http_filter.h ├── php_http_header.c ├── php_http_header.h ├── php_http_header_parser.c ├── php_http_header_parser.h ├── php_http_info.c ├── php_http_info.h ├── php_http_message.c ├── php_http_message.h ├── php_http_message_body.c ├── php_http_message_body.h ├── php_http_message_parser.c ├── php_http_message_parser.h ├── php_http_misc.c ├── php_http_misc.h ├── php_http_negotiate.c ├── php_http_negotiate.h ├── php_http_object.c ├── php_http_object.h ├── php_http_options.c ├── php_http_options.h ├── php_http_params.c ├── php_http_params.h ├── php_http_querystring.c ├── php_http_querystring.h ├── php_http_response_codes.h ├── php_http_url.c ├── php_http_url.h ├── php_http_utf8.h ├── php_http_version.c └── php_http_version.h └── tests ├── bug61444.phpt ├── bug66388.phpt ├── bug66891.phpt ├── bug67932.phpt ├── bug69000.phpt ├── bug69076.phpt ├── bug69313.phpt ├── bug69357.phpt ├── bug71719.phpt ├── bug73055.phpt ├── client001.phpt ├── client002.phpt ├── client003.phpt ├── client004.phpt ├── client005.phpt ├── client006.phpt ├── client007.phpt ├── client008.phpt ├── client009.phpt ├── client010.phpt ├── client011.phpt ├── client012.phpt ├── client013.phpt ├── client014.phpt ├── client015.phpt ├── client016.phpt ├── client017.phpt ├── client018.phpt ├── client019.phpt ├── client020.phpt ├── client021.phpt ├── client022.phpt ├── client023.phpt ├── client024.phpt ├── client025.phpt ├── client026.phpt ├── client027.phpt ├── client028.phpt ├── client029.phpt ├── client030.phpt ├── client031.phpt ├── client032.phpt ├── clientrequest001.phpt ├── clientrequest002.phpt ├── clientrequest003.phpt ├── clientrequest004.phpt ├── clientresponse001.phpt ├── clientresponse002.phpt ├── clientresponse003.phpt ├── cookie001.phpt ├── cookie002.phpt ├── cookie003.phpt ├── cookie004.phpt ├── cookie005.phpt ├── cookie006.phpt ├── cookie007.phpt ├── cookie008.phpt ├── cookie009.phpt ├── cookie010.phpt ├── cookie011.phpt ├── cookie012.phpt ├── data ├── bug71719.bin ├── message_r_content_range.txt ├── message_r_multipart_put.txt ├── message_rr_empty.txt ├── message_rr_empty_chunked.txt ├── message_rr_empty_gzip.txt ├── message_rr_helloworld_chunked.txt └── urls.txt ├── encstream001.phpt ├── encstream002.phpt ├── encstream003.phpt ├── encstream004.phpt ├── encstream005.phpt ├── encstream006.phpt ├── encstream007.phpt ├── encstream008.phpt ├── encstream009.phpt ├── encstream015.phpt ├── encstream016.phpt ├── encstream017.phpt ├── encstream018.phpt ├── encstream019.phpt ├── envrequestbody001.phpt ├── envrequestcookie001.phpt ├── envrequestfiles001.phpt ├── envrequestfiles002.phpt ├── envrequestform.phpt ├── envrequestheader001.phpt ├── envrequestquery.phpt ├── envreset001.phpt ├── envresponse001.phpt ├── envresponse002.phpt ├── envresponse003.phpt ├── envresponse004.phpt ├── envresponse005.phpt ├── envresponse006.phpt ├── envresponse007.phpt ├── envresponse008.phpt ├── envresponse009.phpt ├── envresponse010.phpt ├── envresponse011.phpt ├── envresponse012.phpt ├── envresponse013.phpt ├── envresponse014.phpt ├── envresponse015.phpt ├── envresponse016.phpt ├── envresponse017.phpt ├── envresponse018.phpt ├── envresponsebody001.phpt ├── envresponsebody002.phpt ├── envresponsecodes.phpt ├── envresponsecookie001.phpt ├── envresponseheader001.phpt ├── envresponseranges001.phpt ├── etag001.phpt ├── filterbrotli.phpt ├── filterchunked.phpt ├── filterzlib.phpt ├── gh-issue11.phpt ├── gh-issue12.phpt ├── gh-issue42.phpt ├── gh-issue47.phpt ├── gh-issue48.phpt ├── gh-issue50.phpt ├── gh-issue6.phpt ├── gh-issue63.phpt ├── gh-issue92.phpt ├── header001.phpt ├── header002.phpt ├── header003.phpt ├── header004.phpt ├── header005.phpt ├── header006.phpt ├── header007.phpt ├── header008.phpt ├── header009.phpt ├── headerparser001.phpt ├── headerparser002.phpt ├── headerparser003.phpt ├── helper ├── cookie.inc ├── cookie1.inc ├── cookie2.inc ├── dump.inc ├── env.inc ├── html │ └── index.html ├── http2.crt ├── http2.key ├── pipeline.inc ├── proxy.inc ├── server.inc └── upload.inc ├── info001.phpt ├── info002.phpt ├── message001.phpt ├── message002.phpt ├── message003.phpt ├── message004.phpt ├── message005.phpt ├── message007.phpt ├── message008.phpt ├── message009.phpt ├── message010.phpt ├── message011.phpt ├── message012.phpt ├── message013.phpt ├── message014.phpt ├── message015.phpt ├── message016.phpt ├── messagebody001.phpt ├── messagebody002.phpt ├── messagebody003.phpt ├── messagebody004.phpt ├── messagebody005.phpt ├── messagebody006.phpt ├── messagebody007.phpt ├── messagebody008.phpt ├── messagebody009.phpt ├── messagebody010.phpt ├── messageparser001.phpt ├── messageparser002.phpt ├── negotiate001.phpt ├── params001.phpt ├── params002.phpt ├── params003.phpt ├── params004.phpt ├── params005.phpt ├── params006.phpt ├── params007.phpt ├── params008.phpt ├── params009.phpt ├── params010.phpt ├── params011.phpt ├── params012.phpt ├── params013.phpt ├── params014.phpt ├── params015.phpt ├── params016.phpt ├── params017.phpt ├── phpinfo.phpt ├── querystring001_a.phpt ├── querystring002.phpt ├── querystring003.phpt ├── serialize001.phpt ├── skipif.inc ├── url001.phpt ├── url002.phpt ├── url003.phpt ├── url004.phpt ├── url005.phpt ├── urlparser001.phpt ├── urlparser002.phpt ├── urlparser003.phpt ├── urlparser004.phpt ├── urlparser005.phpt ├── urlparser006.phpt ├── urlparser007.phpt ├── urlparser008.phpt ├── urlparser009.phpt ├── urlparser010.phpt ├── urlparser011.phpt ├── urlparser012.phpt ├── urlparser013.phpt └── version001.phpt /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | notify: 3 | gitter: 4 | default: 5 | url: https://webhooks.gitter.im/e/1f4b7664dcf58cc46314 6 | -------------------------------------------------------------------------------- /.coverity.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP MESSAGE----- 2 | 3 | hQEMAwqQFiRaTnxoAQgArhSb2v6XxX0h5AiNbj72BTfoiXmviWQ9B6zDtQocaivU 4 | 3JEEeUeqOTA1bflW4pCmWnbn4aehDj2uSYgFy2vf4Xu4RCzdu07dC2t9maeP20f2 5 | jOsi6MzKjGTvlnLu+5mNLcM8o4nhSiV4HIiwgQK7Cd79RhQuO5CSuV6tuY199kqV 6 | FzPwFetEhcHmhhlFeXqIjLFAfdttPoEjqS+iyVZw1K4L7D/GWRsVUvKD+FNeZh3I 7 | MtY9Q2j/X4ZAoAG37APGLnaWF92u6enp9v2WPqsCkMAVMr6ZRjSwLmDhnyrpuNMH 8 | jMwk/2nRMuQXrzmh5vIs8NlvajSJlRryDnDTDNoXJtJSAag3HzgnObqUb2H6klQC 9 | kZ+nXBDQlNvuLf2wyBtJy6f8X8XhLGnb67fV2BHg1t9lG8wvRol1qB0cgH9YAneS 10 | nanGvymsS0OKotCKCtLIoYUCTg== 11 | =Ww65 12 | -----END PGP MESSAGE----- 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = tab 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | 11 | [package.xml] 12 | indent_style = space 13 | indent_size = 1 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | 18 | [*.json] 19 | indent_style = space 20 | indent_size = 4 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | package.xml merge=touch 2 | php_http.h merge=touch 3 | CHANGELOG.md merge=touch 4 | .travis.yml merge=touch 5 | /tests/data/bug71719.bin -diff -text 6 | -------------------------------------------------------------------------------- /.github/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: workflows/ci.yml 3 | all: workflows/curl-matrix.yml 4 | 5 | workflows/%.yml: ../scripts/gen_github_workflow_%.php 6 | $<>$@ 7 | 8 | workflows/curl-matrix.yml: ../scripts/curlver.dist 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cproject 2 | .deps 3 | *.dep 4 | .libs/ 5 | .project 6 | /Makefile 7 | Makefile.fragments 8 | Makefile.global 9 | Makefile.objects 10 | acinclude.m4 11 | aclocal.m4 12 | autom4te.cache/ 13 | build/ 14 | config.cache 15 | config.guess 16 | config.h 17 | config.h.in 18 | config.log 19 | config.nice 20 | config.status 21 | config.sub 22 | configure 23 | configure.ac 24 | configure.in 25 | http.la 26 | install-sh 27 | lcov_data 28 | libtool 29 | ltmain.sh 30 | missing 31 | mkinstalldirs 32 | modules/ 33 | pecl_http-*.tgz 34 | *.lo 35 | *.o 36 | run-tests.php 37 | tests/*.diff 38 | tests/*.exp 39 | tests/*.log 40 | tests/*.out 41 | tests/*.php 42 | tests/*.sh 43 | lcov_data 44 | *~ 45 | *.phar 46 | !travis/*.phar 47 | bench/ 48 | vendor/ 49 | /php_http_api.h 50 | /php_http_buffer.h 51 | /php_http_client.h 52 | /php_http_client_curl.h 53 | /php_http_client_curl_event.h 54 | /php_http_client_curl_user.h 55 | /php_http_client_request.h 56 | /php_http_client_response.h 57 | /php_http_cookie.h 58 | /php_http_curl.h 59 | /php_http_encoding.h 60 | /php_http_encoding_zlib.h 61 | /php_http_encoding_brotli.h 62 | /php_http_env.h 63 | /php_http_env_request.h 64 | /php_http_env_response.h 65 | /php_http_etag.h 66 | /php_http_exception.h 67 | /php_http_filter.h 68 | /php_http_header.h 69 | /php_http_header_parser.h 70 | /php_http_info.h 71 | /php_http_message.h 72 | /php_http_message_body.h 73 | /php_http_message_parser.h 74 | /php_http_misc.h 75 | /php_http_negotiate.h 76 | /php_http_object.h 77 | /php_http_options.h 78 | /php_http_params.h 79 | /php_http_querystring.h 80 | /php_http_response_codes.h 81 | /php_http_url.h 82 | /php_http_utf8.h 83 | /php_http_version.h 84 | /tests/helper/server.log 85 | *gcov 86 | *lcov 87 | .vscode 88 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "scripts/ci"] 2 | path = scripts/ci 3 | url = https://github.com/m6w6/pecl-ci.git 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Michael Wallner 2 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | Known Issues 2 | ============ 3 | 4 | Windows: 5 | If you keep getting "SSL connect error" when trying to issue 6 | requests, try another (newer) libeay32.dll/ssleay32.dll pair. 7 | 8 | Internals: 9 | Inflating raw deflated data causes a re-initialization of the inflate 10 | stream where the corresponding window bits are modified to tell libz 11 | to not check for zlib header bytes. This is not preventable AFAICS. 12 | Persistent handles and "cookiestore" request option do interfere, 13 | as libcurl saves the cookies to the file on curl_easy_destroy(), 14 | cookies are not saved until the CURL handle will be recycled. 15 | Thus one would either need to 16 | * run PHP with raphf.persistent_handles.limit = 0 17 | * call raphf\persistent_handles_clean() every request 18 | * call $client->flushCookies(), which is available 19 | since libcurl v7.17.1 and does not work with the 20 | procedural API 21 | HTTP and Proxy authentication information (username/password) can not be 22 | unset with NULL prior libcurl v7.19.6 and separate options for setting 23 | username and password--which work--are only available since v7.19.6. 24 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | HTTP extension for PHP 2 | Michael Wallner 3 | -------------------------------------------------------------------------------- /CVE.md: -------------------------------------------------------------------------------- 1 | # CVE 2 | 3 | List of [CVE](http://cve.mitre.org/)s regarding pecl/http. 4 | 5 | ID | GH-Issue/PHP-Bug | Summary | Fixed in | Commit 6 | --------------|----------------------------------------------------|-----------------------------------------------|--------------------|------- 7 | CVE-2016-5873 | [PHP-71719](https://bugs.php.net/bug.php?id=71719) | Buffer overflow in HTTP url parsing functions | 2.5.6, 3.0.1 | https://github.com/m6w6/ext-http/commit/3724cd76a28be1d6049b5537232e97ac567ae1f5 8 | CVE-2016-7398 | [PHP-73055](https://bugs.php.net/bug.php?id=73055) | Type confusion vulnerability in merge_param() | 2.6.0RC1, 3.1.0RC1 | https://github.com/m6w6/ext-http/commit/17137d4ab1ce81a2cee0fae842340a344ef3da83 9 | CVE-2016-7961 | [PHP-73185](https://bugs.php.net/bug.php?id=73185) | Buffer overflow in HTTP parse_hostinfo() | 2.6.0RC1, 3.1.0RC1 | https://github.com/m6w6/ext-http/commit/ec043079e9915d7d1f4cb06eeadb2c7fca195658 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2015, Michael Wallner . 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | -------------------------------------------------------------------------------- /Makefile.frag: -------------------------------------------------------------------------------- 1 | # provide headers in builddir, so they do not end up in /usr/include/ext/http/src 2 | 3 | PHP_HTTP_HEADERS := $(addprefix $(PHP_HTTP_BUILDDIR)/,$(PHP_HTTP_HEADERS)) 4 | 5 | $(PHP_HTTP_BUILDDIR)/%.h: $(PHP_HTTP_SRCDIR)/src/%.h 6 | @cat >$@ <$< 7 | 8 | $(all_targets): http-build-headers 9 | clean: http-clean-headers 10 | 11 | .PHONY: http-build-headers 12 | http-build-headers: $(PHP_HTTP_HEADERS) 13 | 14 | .PHONY: http-clean-headers 15 | http-clean-headers: 16 | -rm -f $(PHP_HTTP_HEADERS) 17 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Thanks go to the following people, who have contributed to this project: 2 | 3 | Ilia Alshanetsky (ilia at php dot net) 4 | Anatol Belski (ab at php dot net) 5 | Petr Czaderna (petr at hroch dot info) 6 | Remi Collet (remi at php dot net) 7 | Benjamin Eberlei (kontakt at beberlei dot de) 8 | David James (james82 at gmail dot com) 9 | Thomas Landro Johnsen (thomas dot l dot johnsen at gmail dot com) 10 | Clay Loveless (clay at killersoft dot com) 11 | Felipe Pena (felipe at php dot net) 12 | David Sklar (sklar at sklar dot com) 13 | Travis Swicegood (travis at mashery dot com) 14 | Alexey Zakhlestin (indeyets at gmail dot com) 15 | Alexander Zhuravlev (zaa at zaa dot pp dot ru) 16 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * let the message body be a simple query string unless files are added 2 | * php_http_message_serialize reverses the chain twice; remove that 3 | * CURLOPT_PROXY_HEADER and CURLOPT_HEADEROPT 4 | * CURLMOPT_PIPELINING changed to a bitmask -------------------------------------------------------------------------------- /autoconf/pecl/libbrotli.m4: -------------------------------------------------------------------------------- 1 | 2 | AC_DEFUN([PECL_CHECK_LIBBROTLI], [ 3 | PECL_CHECK_LIBBROTLI_COMMON([$1], [$2]) 4 | PECL_CHECK_DONE(libbrotlicommon, [$PECL_VAR([HAVE_LIBBROTLI_COMMON])]) 5 | PECL_CHECK_LIBBROTLI_DEC([$1], [$2]) 6 | PECL_CHECK_DONE(libbrotlidec, [$PECL_VAR([HAVE_LIBBROTLI_DEC])]) 7 | PECL_CHECK_LIBBROTLI_ENC([$1], [$2]) 8 | PECL_CHECK_DONE(libbrotlienc, [$PECL_VAR([HAVE_LIBBROTLI_ENC])]) 9 | 10 | if $PECL_VAR([HAVE_LIBBROTLI_COMMON]) \ 11 | && $PECL_VAR([HAVE_LIBBROTLI_DEC]) \ 12 | && $PECL_VAR([HAVE_LIBBROTLI_ENC]); then 13 | PECL_VAR([HAVE_LIBBROTLI])=true 14 | else 15 | PECL_VAR([HAVE_LIBBROTLI])=false 16 | fi 17 | dnl config.m4 calls PECL_CHECK_DONE once more 18 | PECL_COUNT_CHECKS([+1]) 19 | PECL_SAVE_ENV([CPPFLAGS], [libbrotli]) 20 | PECL_SAVE_ENV([LDFLAGS], [libbrotli]) 21 | PECL_SAVE_ENV([LIBS], [libbrotli]) 22 | ]) 23 | 24 | AC_DEFUN([PECL_CHECK_LIBBROTLI_COMMON], [ 25 | PECL_CHECK_PKGCONFIG(libbrotlicommon, [$1]) 26 | 27 | PECL_HAVE_VERSION(libbrotlicommon, ifelse($2,,1.0,$2), [ 28 | PECL_VAR([HAVE_LIBBROTLI_COMMON])=true 29 | ], [ 30 | PECL_VAR([HAVE_LIBBROTLI_COMMON])=false 31 | ]) 32 | ]) 33 | 34 | AC_DEFUN([PECL_CHECK_LIBBROTLI_DEC], [ 35 | PECL_CHECK_PKGCONFIG(libbrotlidec, [$1]) 36 | 37 | PECL_HAVE_VERSION(libbrotlidec, ifelse($2,,1.0,$2), [ 38 | PECL_VAR([HAVE_LIBBROTLI_DEC])=true 39 | ], [ 40 | PECL_VAR([HAVE_LIBBROTLI_DEC])=false 41 | ]) 42 | ]) 43 | 44 | AC_DEFUN([PECL_CHECK_LIBBROTLI_ENC], [ 45 | PECL_CHECK_PKGCONFIG(libbrotlienc, [$1]) 46 | 47 | PECL_HAVE_VERSION(libbrotlienc, ifelse($2,,1.0,$2), [ 48 | PECL_VAR([HAVE_LIBBROTLI_ENC])=true 49 | ], [ 50 | PECL_VAR([HAVE_LIBBROTLI_ENC])=false 51 | ]) 52 | ]) 53 | -------------------------------------------------------------------------------- /autoconf/pecl/libevent.m4: -------------------------------------------------------------------------------- 1 | 2 | AC_DEFUN([PECL_CHECK_LIBEVENT], [ 3 | PECL_CHECK_PKGCONFIG(libevent, [$1]) 4 | if test -n "$PECL_CHECKED_VERSION(libevent)"; then 5 | PECL_HAVE_VERSION(libevent, 2.0, [ 6 | PECL_DEFINE([HAVE_LIBEVENT2]) 7 | ], [ ]) 8 | ifelse([$2],,,[PECL_HAVE_VERSION(libevent, [$2])]) 9 | AC_CHECK_FUNC(event_base_new,,[ 10 | AC_DEFINE([event_base_new], [event_init], [missing event_base_new() in libevent1]) 11 | ]) 12 | AC_CHECK_FUNC(event_assign,,[ 13 | AC_DEFINE([event_assign(e, b, s, a, cb, d)], [do {\ 14 | event_set(e, s, a, cb, d); \ 15 | event_base_set(b, e);\ 16 | } while(0)], [missing event_assign() in libevent1]) 17 | ]) 18 | fi 19 | ]) -------------------------------------------------------------------------------- /autoconf/pecl/zlib.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl PECL_CHECK_ZLIB( 3 | dnl 4 | dnl Calls PECL_CHECK_CUSTOM(zlib ...) for its tests. 5 | dnl Call PECL_CHECK_DONE(zlib[, success]) yourself when you're done 6 | dnl with any subtests. This is IMPORTANT! 7 | dnl 8 | AC_DEFUN([PECL_CHECK_ZLIB], [ 9 | PECL_CHECK_CUSTOM(zlib, ["$1" "$PHP_ZLIB_DIR" "$PHP_ZLIB"], zlib.h, z, 10 | [$($EGREP "define ZLIB_VERSION" "$path/include/zlib.h" | $SED -e 's/@<:@^0-9\.@:>@//g')]) 11 | ifelse([$2],,,[PECL_HAVE_VERSION(zlib, $2)]) 12 | ]) -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl phpize stub of config9.m4 for pecl/http 2 | dnl $Id: config.m4 214417 2006-06-07 21:05:34Z mike $ 3 | dnl vim: noet ts=1 sw=1 4 | 5 | sinclude(config9.m4) 6 | -------------------------------------------------------------------------------- /php_http.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_EXT_HTTP_H 14 | #define PHP_EXT_HTTP_H 15 | 16 | #define PHP_PECL_HTTP_VERSION "4.2.6" 17 | 18 | extern zend_module_entry http_module_entry; 19 | #define phpext_http_ptr &http_module_entry 20 | 21 | extern int http_module_number; 22 | 23 | #endif /* PHP_EXT_HTTP_H */ 24 | 25 | /* 26 | * Local variables: 27 | * tab-width: 4 28 | * c-basic-offset: 4 29 | * End: 30 | * vim600: noet sw=4 ts=4 fdm=marker 31 | * vim<600: noet sw=4 ts=4 32 | */ 33 | -------------------------------------------------------------------------------- /scripts/bench_select_vs_event.php: -------------------------------------------------------------------------------- 1 | -n -c [-p (enable pipelining)] [-e (use libevent)]\n", $argv[0]); 9 | fprintf(STDERR, "\nDefaults: -u http://localhost/ -n 1000 -c 10\n\n"); 10 | exit(-1); 11 | } 12 | 13 | function push($client, $url, &$n) { 14 | if ($n-- > 0) { 15 | $req = new http\Client\Request("GET", $url); 16 | $client->enqueue($req, function($response) use ($client, $req, $url, &$n) { 17 | global $count; ++$count; 18 | push($client, $url, $n); 19 | return true; // dequeue 20 | }); 21 | } 22 | } 23 | 24 | isset($argv) or $argv = $_SERVER['argv']; 25 | defined('STDERR') or define('STDERR', fopen('php://stderr', 'w')); 26 | 27 | $opts = getopt("u:c:n:e"); 28 | isset($opts["u"]) or $opts["u"] = "http://localhost/"; 29 | isset($opts["c"]) or $opts["c"] = 10; 30 | isset($opts["n"]) or $opts["n"] = 1000; 31 | 32 | $argc > 1 or usage(); 33 | 34 | $time = microtime(true); 35 | $count = 0; 36 | $client = new http\Client; 37 | 38 | $client->enablePipelining($opts["p"]===false); 39 | $client->enableEvents($opts["e"]===false); 40 | 41 | for ($i = 0, $x = $opts["n"]; $i < $opts["c"]; ++$i) { 42 | push($client, $opts["u"], $x); 43 | } 44 | 45 | try { 46 | $client->send(); 47 | } catch (Exception $e) { 48 | echo $e; 49 | } 50 | 51 | printf("\n> %10.6fs (%3.2fM)\n", microtime(true)-$time, memory_get_peak_usage(true)/1024/1024); 52 | 53 | $count == $opts["n"] or printf("\nOnly %d finished\n", $count); 54 | -------------------------------------------------------------------------------- /scripts/coverity.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | exec 1> /dev/null 5 | 6 | pushd $(dirname $(dirname $0)) 7 | 8 | COVERITY_BIN=$(PATH="$PATH:/opt/coverity/bin" which cov-build) 9 | COVERITY_PROJECT=$(git ls-remote --get-url origin | sed 's/^.*:\(.*\)\.git$/\1/') 10 | COVERITY_BUILD_DATE=$(date --iso-8601=seconds) 11 | COVERITY_BUILD_BRANCH=$(git rev-parse --abbrev-ref HEAD) 12 | COVERITY_BUILD_DIR=$(mktemp -td coverity.XXXXXX) 13 | 14 | COVERITY_SCAN_TOKEN=$(gpg --quiet --decrypt < .coverity.asc) 15 | 16 | phpize 17 | ./configure 18 | make clean 19 | 20 | 21 | $COVERITY_BIN --dir $COVERITY_BUILD_DIR/cov-int make -j8 22 | 23 | echo >&2 24 | echo -n "Submit results to scan.coverity.com? (y/N) " >&2 25 | read submit 26 | echo >&2 27 | 28 | if test "$submit" != "y"; then 29 | exit 30 | fi 31 | 32 | pushd $COVERITY_BUILD_DIR 33 | tar -czf cov-int{.tgz,} 34 | popd 35 | 36 | curl -sS\ 37 | --form "token=$COVERITY_SCAN_TOKEN" \ 38 | --form "version=$COVERITY_BUILD_BRANCH" \ 39 | --form "email=mike@php.net" \ 40 | --form "description=$COVERITY_BUILD_DATE" \ 41 | --form "file=@$COVERITY_BUILD_DIR/cov-int.tgz" \ 42 | --url "https://scan.coverity.com/builds?project=$COVERITY_PROJECT" >&2 43 | 44 | rm -r $COVERITY_BUILD_DIR 45 | 46 | popd 47 | -------------------------------------------------------------------------------- /scripts/curlver.dist: -------------------------------------------------------------------------------- 1 | # latest is 8.9.1 ATM 2 | # 7.21.5-7.29.0 fail to configure on gh actions 3 | 4 | # always test against a few recent 5 | latest: master 8.10.1 8.9.1 8.8.0 8.7.1 8.6.0 8.5.0 6 | # various linux distros 7 | current: 8.2.1 8.1.1 7.88.1 7.81.0 8 | # and a couple older 9 | oldest: 7.78.0 7.76.1 7.61.1 10 | 11 | # 7.64.1 fails client tests because of superfluous infof() calls 12 | # 7.64.0 fails client cookie test because of curl/curl#3613 13 | -------------------------------------------------------------------------------- /src/php_http_client_curl_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_CLIENT_CURL_EVENT_H 14 | #define PHP_HTTP_CLIENT_CURL_EVENT_H 15 | 16 | #if PHP_HTTP_HAVE_LIBCURL 17 | #if PHP_HTTP_HAVE_LIBEVENT 18 | 19 | php_http_client_curl_ops_t *php_http_client_curl_event_ops_get(); 20 | 21 | #endif 22 | #endif 23 | 24 | #endif 25 | 26 | /* 27 | * Local variables: 28 | * tab-width: 4 29 | * c-basic-offset: 4 30 | * End: 31 | * vim600: noet sw=4 ts=4 fdm=marker 32 | * vim<600: noet sw=4 ts=4 33 | */ 34 | -------------------------------------------------------------------------------- /src/php_http_client_request.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_CLIENT_REQUEST_H 14 | #define PHP_HTTP_CLIENT_REQUEST_H 15 | 16 | PHP_HTTP_API zend_class_entry *php_http_get_client_request_class_entry(void); 17 | PHP_MINIT_FUNCTION(http_client_request); 18 | 19 | #endif /* PHP_HTTP_CLIENT_REQUEST_H */ 20 | 21 | /* 22 | * Local variables: 23 | * tab-width: 4 24 | * c-basic-offset: 4 25 | * End: 26 | * vim600: noet sw=4 ts=4 fdm=marker 27 | * vim<600: noet sw=4 ts=4 28 | */ 29 | -------------------------------------------------------------------------------- /src/php_http_client_response.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_CLIENT_RESPONSE_H 14 | #define PHP_HTTP_CLIENT_RESPONSE_H 15 | 16 | PHP_HTTP_API zend_class_entry *php_http_get_client_response_class_entry(void); 17 | PHP_MINIT_FUNCTION(http_client_response); 18 | 19 | #endif /* PHP_HTTP_CLIENT_RESPONSE_H */ 20 | 21 | 22 | /* 23 | * Local variables: 24 | * tab-width: 4 25 | * c-basic-offset: 4 26 | * End: 27 | * vim600: noet sw=4 ts=4 fdm=marker 28 | * vim<600: noet sw=4 ts=4 29 | */ 30 | -------------------------------------------------------------------------------- /src/php_http_curl.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_CURL_H 14 | #define PHP_HTTP_CURL_H 15 | 16 | #if PHP_HTTP_HAVE_LIBCURL 17 | 18 | #include 19 | #define PHP_HTTP_CURL_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= (((x)<<16) + ((y)<<8) + (z))) 20 | #define PHP_HTTP_CURL_FEATURE(f) (curl_version_info(CURLVERSION_NOW)->features & (f)) 21 | 22 | #if !PHP_HTTP_CURL_VERSION(7,21,5) 23 | # define CURLE_UNKNOWN_OPTION CURLE_FAILED_INIT 24 | #endif 25 | 26 | PHP_MINIT_FUNCTION(http_curl); 27 | PHP_MSHUTDOWN_FUNCTION(http_curl); 28 | 29 | #endif /* PHP_HTTP_HAVE_LIBCURL */ 30 | 31 | #endif /* PHP_HTTP_CURL_H */ 32 | 33 | /* 34 | * Local variables: 35 | * tab-width: 4 36 | * c-basic-offset: 4 37 | * End: 38 | * vim600: noet sw=4 ts=4 fdm=marker 39 | * vim<600: noet sw=4 ts=4 40 | */ 41 | 42 | -------------------------------------------------------------------------------- /src/php_http_env_request.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_ENV_REQUEST_H 14 | #define PHP_HTTP_ENV_REQUEST_H 15 | 16 | PHP_HTTP_API zend_class_entry *php_http_get_env_request_class_entry(void); 17 | PHP_MINIT_FUNCTION(http_env_request); 18 | 19 | #endif 20 | 21 | /* 22 | * Local variables: 23 | * tab-width: 4 24 | * c-basic-offset: 4 25 | * End: 26 | * vim600: noet sw=4 ts=4 fdm=marker 27 | * vim<600: noet sw=4 ts=4 28 | */ 29 | -------------------------------------------------------------------------------- /src/php_http_etag.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_ETAG_H 14 | #define PHP_HTTP_ETAG_H 15 | 16 | #include "ext/hash/php_hash.h" 17 | 18 | typedef struct php_http_etag { 19 | const php_hash_ops *ops; 20 | char ctx[1]; 21 | } php_http_etag_t; 22 | 23 | PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode); 24 | PHP_HTTP_API size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len); 25 | PHP_HTTP_API char *php_http_etag_finish(php_http_etag_t *e); 26 | 27 | static inline char *php_http_etag_digest(const unsigned char *digest, int len) 28 | { 29 | static const char hexdigits[17] = "0123456789abcdef"; 30 | int i; 31 | char *hex = emalloc(len * 2 + 1); 32 | char *ptr = hex; 33 | 34 | for (i = 0; i < len; ++i) { 35 | *ptr++ = hexdigits[digest[i] >> 4]; 36 | *ptr++ = hexdigits[digest[i] & 0xF]; 37 | } 38 | *ptr = '\0'; 39 | 40 | return hex; 41 | } 42 | 43 | #endif /* PHP_HTTP_ETAG_H */ 44 | 45 | /* 46 | * Local variables: 47 | * tab-width: 4 48 | * c-basic-offset: 4 49 | * End: 50 | * vim600: noet sw=4 ts=4 fdm=marker 51 | * vim<600: noet sw=4 ts=4 52 | */ 53 | 54 | -------------------------------------------------------------------------------- /src/php_http_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_FILTER_H 14 | #define PHP_HTTP_FILTER_H 15 | 16 | PHP_HTTP_API php_stream_filter_factory php_http_filter_factory; 17 | PHP_MINIT_FUNCTION(http_filter); 18 | 19 | #endif 20 | 21 | /* 22 | * Local variables: 23 | * tab-width: 4 24 | * c-basic-offset: 4 25 | * End: 26 | * vim600: noet sw=4 ts=4 fdm=marker 27 | * vim<600: noet sw=4 ts=4 28 | */ 29 | 30 | -------------------------------------------------------------------------------- /src/php_http_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: http | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2004-2014, Michael Wallner | 10 | +--------------------------------------------------------------------+ 11 | */ 12 | 13 | #ifndef PHP_HTTP_VERSION_H 14 | #define PHP_HTTP_VERSION_H 15 | 16 | typedef struct php_http_version { 17 | unsigned major; 18 | unsigned minor; 19 | } php_http_version_t; 20 | 21 | PHP_HTTP_API php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor); 22 | PHP_HTTP_API php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str); 23 | PHP_HTTP_API void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post); 24 | PHP_HTTP_API void php_http_version_dtor(php_http_version_t *v); 25 | PHP_HTTP_API void php_http_version_free(php_http_version_t **v); 26 | 27 | #endif /* PHP_HTTP_VERSION_H */ 28 | 29 | 30 | /* 31 | * Local variables: 32 | * tab-width: 4 33 | * c-basic-offset: 4 34 | * End: 35 | * vim600: noet sw=4 ts=4 fdm=marker 36 | * vim<600: noet sw=4 ts=4 37 | */ 38 | 39 | -------------------------------------------------------------------------------- /tests/bug61444.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #61444 (. become _ in query strings due to php_default_treat_data()) 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 'utm_source=changed'), http\Url::JOIN_QUERY), PHP_EOL, PHP_EOL; 16 | 17 | // Replacing the host 18 | echo new http\Url($url, array('host' => 'www.google.com')), PHP_EOL, PHP_EOL; 19 | 20 | // Generating a query string from scratch 21 | echo new http\QueryString(array( 22 | 'bar.baz' => 'blah', 23 | 'utm_source' => 'google', 24 | 'utm_campaign' => 'somethingelse', 25 | 'blat' => null, 26 | )), PHP_EOL, PHP_EOL; 27 | ?> 28 | DONE 29 | --EXPECT-- 30 | http://www.example.com/foobar?bar.baz=blah&utm_source=google&utm_campaign=somethingelse&blat 31 | 32 | http://www.example.com/foobar?bar.baz=blah&utm_source=changed&utm_campaign=somethingelse&blat 33 | 34 | http://www.google.com/foobar?bar.baz=blah&utm_source=google&utm_campaign=somethingelse&blat 35 | 36 | bar.baz=blah&utm_source=google&utm_campaign=somethingelse 37 | 38 | DONE 39 | -------------------------------------------------------------------------------- /tests/bug66388.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #66388 (Crash on POST with Content-Length:0 and untouched body) 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 0 26 | ) 27 | ); 28 | $client->setOptions(["timeout" => 30]); 29 | $client->enqueue($request); 30 | echo $client->send()->getResponse()->getResponseCode(); 31 | }); 32 | 33 | ?> 34 | 35 | ===DONE=== 36 | --EXPECTF-- 37 | Test 38 | 200 39 | ===DONE=== 40 | -------------------------------------------------------------------------------- /tests/bug66891.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #66891 (Unexpected HTTP 401 after NTLM authentication) 3 | --SKIPIF-- 4 | 7 | --GET-- 8 | dummy=1 9 | --FILE-- 10 | setResponseCode(200); 14 | $r->send(); 15 | var_dump(http\Env::getResponseCode()); 16 | ?> 17 | --EXPECT-- 18 | int(200) -------------------------------------------------------------------------------- /tests/bug67932.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #67932 (php://input always empty) 3 | --SKIPIF-- 4 | 7 | --PUT-- 8 | Content-Type: text/xml 9 | 10 | 11 | test 12 | --FILE-- 13 | 16 | --EXPECT-- 17 | 18 | test -------------------------------------------------------------------------------- /tests/bug69000.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #69000 (http\Url breaks down with very long URL query strings) 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 12 | 13 | ===DONE=== 14 | --EXPECT-- 15 | Test 16 | http://foo.bar/?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 17 | ===DONE=== 18 | -------------------------------------------------------------------------------- /tests/bug69076.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #69076 (URL parsing throws exception on empty query string) 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 12 | 13 | ===DONE=== 14 | --EXPECT-- 15 | Test 16 | http://foo.bar/ 17 | ===DONE=== 18 | -------------------------------------------------------------------------------- /tests/bug69313.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #69313 (http\Client doesn't send GET body) 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setHeader("Content-Type", "text/plain"); 19 | $request->getBody()->append("foo"); 20 | $client = new http\Client(); 21 | $client->enqueue($request); 22 | $client->send(); 23 | dump_message(null, $client->getResponse()); 24 | }); 25 | 26 | ?> 27 | 28 | Done 29 | --EXPECTF-- 30 | Test 31 | HTTP/1.1 200 OK 32 | Accept-Ranges: bytes 33 | Content-Length: %d 34 | Etag: "%s" 35 | X-Original-Transfer-Encoding: chunked 36 | X-Request-Content-Length: 3 37 | 38 | GET / HTTP/1.1 39 | Accept: */* 40 | Content-Length: 3 41 | Content-Type: text/plain 42 | Host: localhost:%d 43 | User-Agent: %s 44 | X-Original-Content-Length: 3 45 | 46 | foo 47 | Done 48 | -------------------------------------------------------------------------------- /tests/bug69357.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #69357 (HTTP/1.1 100 Continue overriding subsequent 200 response code with PUT request) 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | append("foo"); 17 | $r = new \http\Client\Request("PUT", "http://localhost:$port/", array(), $b); 18 | $c = new \http\Client; 19 | $c->setOptions(array("expect_100_timeout" => 0)); 20 | $c->enqueue($r)->send(); 21 | 22 | var_dump($c->getResponse($r)->getInfo()); 23 | var_dump($c->getResponse($r)->getHeaders()); 24 | }); 25 | 26 | ?> 27 | ===DONE=== 28 | --EXPECTF-- 29 | Test 30 | string(15) "HTTP/1.1 200 OK" 31 | array(4) { 32 | ["Accept-Ranges"]=> 33 | string(5) "bytes" 34 | ["Etag"]=> 35 | string(10) ""%x"" 36 | ["X-Original-Transfer-Encoding"]=> 37 | string(7) "chunked" 38 | ["Content-Length"]=> 39 | int(%d) 40 | } 41 | ===DONE=== 42 | -------------------------------------------------------------------------------- /tests/bug71719.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #71719 (Buffer overflow in HTTP url parsing functions) 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | zend.exception_ignore_args=off 9 | --FILE-- 10 | 19 | 20 | ===DONE=== 21 | --EXPECTF-- 22 | Test 23 | %r(exception ')?%rhttp\Exception\BadMessageException%r(' with message '|: )%rhttp\Message::__construct(): Could not parse HTTP protocol version 'HTTP/%s.0'%r'?%r in %sbug71719.php:5 24 | Stack trace: 25 | #0 %sbug71719.php(5): http\Message->__construct('%r(\?\?|\\x80\\xAC)%rTd 5 HTTP/1.1...', false) 26 | #1 {main} 27 | ===DONE=== 28 | -------------------------------------------------------------------------------- /tests/bug73055.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #73055 (Type confusion vulnerability in merge_param()) 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | zend.exception_ignore_args=off 9 | --FILE-- 10 | 20 | 21 | ===DONE=== 22 | --EXPECTF-- 23 | Test 24 | %r(exception ')?%rhttp\Exception\BadQueryStringException%r(' with message '|: )%rhttp\QueryString::__construct(): Max input nesting level of %d exceeded%r'?%r in %sbug73055.php:%d 25 | Stack trace: 26 | #0 %sbug73055.php(%d): http\QueryString->__construct('[[[[[[[[[[[[[[[...') 27 | #1 {main} 28 | ===DONE=== 29 | -------------------------------------------------------------------------------- /tests/client001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client drivers 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | Done 19 | --EXPECTREGEX-- 20 | Test 21 | (?:bool\(true\) 22 | )+Done 23 | -------------------------------------------------------------------------------- /tests/client002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client observer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | getProgressInfo($request); 22 | if ($progress->info !== "prepare" && $compare && $compare != $progress) { 23 | var_dump($progress, $compare); 24 | } 25 | } 26 | } 27 | 28 | server("proxy.inc", function($port, $stdin, $stdout, $stderr) { 29 | foreach (http\Client::getAvailableDrivers() as $driver) { 30 | $client = new http\Client($driver); 31 | $client->attach(new Observer); 32 | $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/")); 33 | $client->send(); 34 | } 35 | }); 36 | 37 | ?> 38 | 39 | Done 40 | --EXPECTREGEX-- 41 | Test 42 | P+ 43 | Done 44 | -------------------------------------------------------------------------------- /tests/client003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client once & wait 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | enqueue($request); 22 | 23 | while ($client->once()) { 24 | $client->wait(.1); 25 | } 26 | 27 | if (!$client->getResponse()) { 28 | var_dump($client); 29 | } 30 | } 31 | }); 32 | ?> 33 | Done 34 | --EXPECT-- 35 | Test 36 | Done 37 | -------------------------------------------------------------------------------- /tests/client004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client reset 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enqueue($request)->send(); 21 | if (!($client->getResponse($request) instanceof http\Client\Response)) { 22 | var_dump($client); 23 | } 24 | try { 25 | $client->enqueue($request); 26 | } catch (Exception $e) { 27 | echo $e->getMessage(),"\n"; 28 | } 29 | $client->reset(); 30 | if (($response = $client->getResponse())) { 31 | var_dump($response); 32 | } 33 | $client->enqueue($request); 34 | } 35 | }); 36 | ?> 37 | Done 38 | --EXPECTREGEX-- 39 | Test 40 | (?:Failed to enqueue request; request already in queue 41 | )+Done 42 | -------------------------------------------------------------------------------- /tests/client005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client response callback 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enqueue(new http\Client\Request("GET", "http://localhost:$port"), function($response) { 19 | echo "R\n"; 20 | if (!($response instanceof http\Client\Response)) { 21 | var_dump($response); 22 | } 23 | }); 24 | $client->send(); 25 | } 26 | }); 27 | 28 | ?> 29 | Done 30 | --EXPECTREGEX-- 31 | Test 32 | (?:R 33 | )+Done 34 | -------------------------------------------------------------------------------- /tests/client006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client response callback + dequeue 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enqueue($request, "response"); 32 | $client->send(); 33 | try { 34 | $client->dequeue($request); 35 | } catch (Exception $e) { 36 | echo $e->getMessage(),"\n"; 37 | } 38 | } 39 | } 40 | }); 41 | 42 | ?> 43 | Done 44 | --EXPECTREGEX-- 45 | Test 46 | (?:(?:R 47 | Failed to dequeue request; request not in queue 48 | )+)+Done 49 | -------------------------------------------------------------------------------- /tests/client007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client response callback + requeue 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | requeue($request, "response"); 29 | $client->send(); 30 | } 31 | } 32 | }); 33 | 34 | ?> 35 | Done 36 | --EXPECTREGEX-- 37 | Test 38 | (?:R 39 | R 40 | )+Done 41 | -------------------------------------------------------------------------------- /tests/client008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client pipelining 3 | --SKIPIF-- 4 | =")) { 8 | die("skip CURL_VERSION >= 7.62 -- pipelining disabled\n"); 9 | } 10 | ?> 11 | --FILE-- 12 | configure(array("pipelining" => true, "use_eventloop" => true)); 25 | 26 | $client->enqueue($request); 27 | $client->send(); 28 | 29 | $client->enqueue(clone $request); 30 | $client->enqueue(clone $request); 31 | 32 | $client->send(); 33 | 34 | while ($client->getResponse()) { 35 | echo "R\n"; 36 | } 37 | }); 38 | 39 | ?> 40 | Done 41 | --EXPECTREGEX-- 42 | Test 43 | (?:R 44 | R 45 | R 46 | )+Done 47 | -------------------------------------------------------------------------------- /tests/client009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client static cookies 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setCookies(array("test" => "bar")); 24 | $client->addCookies(array("foo" => "test")); 25 | 26 | $request = new http\Client\Request("GET", "http://localhost:$port"); 27 | $client->enqueue($request); 28 | $client->send(); 29 | echo $client->getResponse()->getBody()->toString(); 30 | 31 | $request->setOptions(array("cookies" => x($client->getCookies()))); 32 | $client->requeue($request); 33 | $client->send(); 34 | 35 | echo $client->getResponse()->getBody()->toString(); 36 | }); 37 | ?> 38 | Done 39 | --EXPECT-- 40 | Test 41 | Array 42 | ( 43 | [test] => bar 44 | [foo] => test 45 | ) 46 | Array 47 | ( 48 | [test] => test 49 | [foo] => bar 50 | ) 51 | Done 52 | -------------------------------------------------------------------------------- /tests/client010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client upload 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | Array 18 | \( 19 | \[name\] \=\> client010\.php 20 | \[type\] \=\> text\/plain 21 | \[size\] \=\> \d+ 22 | \) 23 | 24 | \) 25 | )+/'; 26 | 27 | server("env.inc", function($port) use($RE) { 28 | 29 | $request = new http\Client\Request("POST", "http://localhost:$port"); 30 | $request->getBody()->addForm(null, array("file"=>__FILE__, "name"=>"upload", "type"=>"text/plain")); 31 | 32 | foreach (http\Client::getAvailableDrivers() as $driver) { 33 | $client = new http\Client($driver); 34 | $client->enqueue($request)->send(); 35 | if (!preg_match($RE, $s = $client->getResponse()->getBody()->toString())) { 36 | echo($s); 37 | } 38 | } 39 | }); 40 | ?> 41 | Done 42 | --EXPECT-- 43 | Test 44 | Done 45 | -------------------------------------------------------------------------------- /tests/client011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client history 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | append("foobar"); 18 | 19 | $request = new http\Client\Request; 20 | $request->setBody($body); 21 | $request->setRequestMethod("POST"); 22 | $request->setRequestUrl("http://localhost:$port"); 23 | 24 | $client = new http\Client; 25 | $client->recordHistory = true; 26 | 27 | $client->enqueue($request)->send(); 28 | echo $client->getHistory()->toString(true); 29 | 30 | $client->requeue($request)->send(); 31 | echo $client->getHistory()->toString(true); 32 | }); 33 | ?> 34 | Done 35 | --EXPECTF-- 36 | Test 37 | POST http://localhost:%d/ HTTP/1.1 38 | Content-Length: 6 39 | 40 | foobar 41 | HTTP/1.1 200 OK 42 | Accept-Ranges: bytes 43 | X-Request-Content-Length: 6 44 | X-Original-Transfer-Encoding: chunked 45 | Content-Length: 19 46 | 47 | string(6) "foobar" 48 | 49 | POST http://localhost:%d/ HTTP/1.1 50 | Content-Length: 6 51 | 52 | foobar 53 | HTTP/1.1 200 OK 54 | Accept-Ranges: bytes 55 | X-Request-Content-Length: 6 56 | X-Original-Transfer-Encoding: chunked 57 | Content-Length: 19 58 | 59 | string(6) "foobar" 60 | 61 | POST http://localhost:%d/ HTTP/1.1 62 | Content-Length: 6 63 | 64 | foobar 65 | HTTP/1.1 200 OK 66 | Accept-Ranges: bytes 67 | X-Request-Content-Length: 6 68 | X-Original-Transfer-Encoding: chunked 69 | Content-Length: 19 70 | 71 | string(6) "foobar" 72 | 73 | Done 74 | -------------------------------------------------------------------------------- /tests/client012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client ssl 3 | --SKIPIF-- 4 | 15 | --FILE-- 16 | setSslOptions(array("verifypeer" => true)); 22 | $client->addSslOptions(array("verifyhost" => 2)); 23 | var_dump( 24 | array( 25 | "verifypeer" => true, 26 | "verifyhost" => 2, 27 | ) === $client->getSslOptions() 28 | ); 29 | 30 | $client->attach($observer = new class implements SplObserver { 31 | public $data = []; 32 | 33 | #[ReturnTypeWillChange] 34 | function update(SplSubject $client, $req = null, $progress = null) { 35 | $ti = $client->getTransferInfo($req); 36 | if (isset($ti->tls_session["internals"])) { 37 | foreach ((array) $ti->tls_session["internals"] as $key => $val) { 38 | if (!isset($this->data[$key]) || $this->data[$key] < $val) { 39 | $this->data[$key] = $val; 40 | } 41 | } 42 | } 43 | } 44 | }); 45 | 46 | $client->enqueue($req = new http\Client\Request("GET", "https://twitter.com/")); 47 | $client->send(); 48 | 49 | switch ($client->getTransferInfo($req)->tls_session["backend"]) { 50 | case "openssl": 51 | case "gnutls": 52 | if (count($observer->data) < 1) { 53 | printf("%s: failed count(ssl.internals) >= 1\n", $client->getTransferInfo($req)->tls_session["backend"]); 54 | var_dump($observer); 55 | exit; 56 | } 57 | break; 58 | default: 59 | break; 60 | } 61 | ?> 62 | Done 63 | --EXPECTF-- 64 | Test 65 | bool(true) 66 | Done 67 | -------------------------------------------------------------------------------- /tests/client014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | reset content length when resetting body 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setBody(new http\Message\Body(fopen(__FILE__, "r"))); 16 | $client->enqueue($request); 17 | var_dump($request->getHeader("Content-Length")); 18 | $request->setBody(new http\Message\Body); 19 | $client->requeue($request); 20 | var_dump($request->getHeader("Content-Length")); 21 | ?> 22 | ===DONE=== 23 | --EXPECTF-- 24 | Test 25 | int(379) 26 | bool(false) 27 | ===DONE=== 28 | -------------------------------------------------------------------------------- /tests/client015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | http client event base 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | configure(array("use_eventloop" => true)); 20 | $client2->configure(array("use_eventloop" => true)); 21 | 22 | $client1->enqueue(new http\Client\Request("GET", "http://localhost:$port/")); 23 | $client2->enqueue(new http\Client\Request("GET", "http://localhost:$port/")); 24 | 25 | $client1->send(); 26 | 27 | if (($r = $client1->getResponse())) { 28 | var_dump($r->getTransferInfo("response_code")); 29 | } 30 | if (($r = $client2->getResponse())) { 31 | var_dump($r->getTransferInfo("response_code")); 32 | } 33 | 34 | }); 35 | ?> 36 | DONE 37 | --EXPECT-- 38 | Test 39 | int(200) 40 | DONE 41 | -------------------------------------------------------------------------------- /tests/client016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client once & wait with events 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | configure(array("use_eventloop" => true)); 21 | $client->enqueue($request); 22 | 23 | while ($client->once()) { 24 | $client->wait(.1); 25 | } 26 | 27 | if (!$client->getResponse()) { 28 | var_dump($client); 29 | } 30 | } 31 | }); 32 | ?> 33 | Done 34 | --EXPECT-- 35 | Test 36 | Done 37 | -------------------------------------------------------------------------------- /tests/client017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client request gzip 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setOptions(array("compress" => true)); 20 | 21 | $client->enqueue($request); 22 | $client->send(); 23 | 24 | echo $client->getResponse(); 25 | }); 26 | ?> 27 | ===DONE=== 28 | --EXPECTF-- 29 | Test 30 | HTTP/1.1 200 OK 31 | Accept-Ranges: bytes 32 | X-Request-Content-Length: 0 33 | Vary: Accept-Encoding 34 | Etag: "%s" 35 | X-Original-Transfer-Encoding: chunked 36 | X-Original-Content-Encoding: deflate 37 | ===DONE=== 38 | 39 | -------------------------------------------------------------------------------- /tests/client018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client pipelining 3 | --SKIPIF-- 4 | =")) { 8 | die("skip CURL_VERSION >= 7.62 -- pipelining disabled\n"); 9 | } 10 | ?> 11 | --FILE-- 12 | getHeader("X-Req"),"\n"; 20 | } 21 | 22 | server("pipeline.inc", function($port, $stdin, $stdout, $stderr) { 23 | /* tell the server we're about to send 3 pipelined messages */ 24 | fputs($stdin, "3\n"); 25 | 26 | $client = new http\Client(null); 27 | $client->configure(array("pipelining" => true, "max_host_connections" => 0)); 28 | 29 | /* this is just to let curl know the server may be capable of pipelining */ 30 | $client->enqueue(new http\Client\Request("GET", "http://localhost:$port"), "dump"); 31 | $client->send(); 32 | 33 | $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/1"), "dump"); 34 | $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/2"), "dump"); 35 | $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/3"), "dump"); 36 | $client->send(); 37 | }); 38 | 39 | ?> 40 | ===DONE=== 41 | --EXPECT-- 42 | Test 43 | / 44 | /1 45 | /2 46 | /3 47 | ===DONE=== 48 | -------------------------------------------------------------------------------- /tests/client019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client proxy - send proxy headers for a proxy request 3 | --SKIPIF-- 4 | getAvailableOptions()) 10 | or die("skip need libcurl with CURLOPT_PROXYHEADER support\n"); 11 | ?> 12 | --FILE-- 13 | setOptions(array( 25 | "timeout" => 10, 26 | "proxytunnel" => true, 27 | "proxyheader" => array("Hello" => "there!"), 28 | "proxyhost" => "localhost", 29 | "proxyport" => $port, 30 | )); 31 | try { 32 | $c->enqueue($r)->send(); 33 | } catch (Exception $e) { 34 | echo $e; 35 | } 36 | echo $c->getResponse()->getBody(); 37 | }); 38 | 39 | ?> 40 | ===DONE=== 41 | --EXPECTF-- 42 | Test 43 | Server on port %d 44 | CONNECT www.example.com:80 HTTP/1.1 45 | Hello: there! 46 | Host: www.example.com:80 47 | %r(Proxy-Connection: Keep-Alive 48 | )?%rUser-Agent: PECL_HTTP/%s PHP/%s libcurl/%s 49 | 50 | ===DONE=== 51 | -------------------------------------------------------------------------------- /tests/client020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client proxy - don't send proxy headers for a standard request 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setOptions(array( 20 | "timeout" => 3, 21 | "proxyheader" => array("Hello" => "there!"), 22 | )); 23 | try { 24 | $c->enqueue($r)->send(); 25 | } catch (Exception $e) { 26 | echo $e; 27 | } 28 | echo $c->getResponse()->getBody(); 29 | unset($r, $client); 30 | }); 31 | 32 | ?> 33 | ===DONE=== 34 | --EXPECTF-- 35 | Test 36 | Server on port %d 37 | GET / HTTP/1.1 38 | Accept: */* 39 | Host: localhost:%d 40 | User-Agent: PECL_HTTP/%s PHP/%s libcurl/%s 41 | 42 | ===DONE=== 43 | -------------------------------------------------------------------------------- /tests/client022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client http2 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | setOptions([ 19 | "protocol" => http\Client\Curl\HTTP_VERSION_2_0, 20 | "ssl" => [ 21 | "cainfo" => __DIR__."/helper/http2.crt", 22 | "verifypeer" => false, // needed for NSS without PEM support 23 | ] 24 | ]); 25 | 26 | $request = new http\Client\Request("GET", "https://localhost:$port"); 27 | $client->enqueue($request); 28 | echo $client->send()->getResponse(); 29 | }); 30 | 31 | ?> 32 | ===DONE=== 33 | --EXPECTF-- 34 | Test 35 | HTTP/2 200 36 | %a 37 | 38 | 39 | 40 | 41 | 42 | HTTP2 43 | 44 | 45 | Nothing to see here. 46 | 47 | 48 | ===DONE=== 49 | -------------------------------------------------------------------------------- /tests/client023.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client available options and configuration 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | getOptions())) { 15 | var_dump($options); 16 | } 17 | $client->setOptions($avail = $client->getAvailableOptions()); 18 | $opt = $client->getOptions(); 19 | 20 | foreach ($avail as $k => $v) { 21 | if (is_array($v)) { 22 | $oo = $opt[$k]; 23 | foreach ($v as $kk => $vv) { 24 | if (isset($vv) && $oo[$kk] !== $vv) { 25 | var_dump(array($kk => array($vv, $oo[$kk]))); 26 | } 27 | } 28 | } else if (isset($v) && $opt[$k] !== $v) { 29 | var_dump(array($k => array($v, $opt[$k]))); 30 | } 31 | } 32 | var_dump($client === $client->configure($client->getAvailableConfiguration())); 33 | 34 | ?> 35 | ===DONE=== 36 | --EXPECT-- 37 | Test 38 | bool(true) 39 | ===DONE=== 40 | -------------------------------------------------------------------------------- /tests/client024.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client deprecated methods 3 | --SKIPIF-- 4 | 10 | --FILE-- 11 | enableEvents(false); 17 | $client->enablePipelining(false); 18 | 19 | ?> 20 | ===DONE=== 21 | --EXPECTF-- 22 | Test 23 | 24 | Deprecated: Method http\Client::enableEvents() is deprecated in %sclient024.php on line %d 25 | 26 | Deprecated: Method http\Client::enablePipelining() is deprecated in %sclient024.php on line %d 27 | ===DONE=== 28 | -------------------------------------------------------------------------------- /tests/client025.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client seek 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setOptions(array("resume" => 1, "expect_100_timeout" => 0)); 20 | $request->getBody()->append("123"); 21 | dump_message(null, $client->enqueue($request)->send()->getResponse()); 22 | }); 23 | // Content-length is 2 instead of 3 in older libcurls 24 | ?> 25 | ===DONE=== 26 | --EXPECTF-- 27 | Test 28 | HTTP/1.1 200 OK 29 | Accept-Ranges: bytes 30 | Content-Length: %d 31 | Etag: "%x" 32 | X-Original-Transfer-Encoding: chunked 33 | X-Request-Content-Length: 2 34 | 35 | PUT / HTTP/1.1 36 | Accept: */* 37 | Content-Length: %d 38 | Content-Range: bytes 1-2/3 39 | %r(Expect: 100-continue 40 | )?%rHost: localhost:%d 41 | User-Agent: %s 42 | X-Original-Content-Length: %d 43 | 44 | 23===DONE=== 45 | -------------------------------------------------------------------------------- /tests/client026.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client stream 128M 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | setContentType("application/octet-stream"); 20 | for ($i = 0, $data = str_repeat("a",1024); $i < 128*1024; ++$i) { 21 | $request->getBody()->append($data); 22 | } 23 | $request->setOptions(array("timeout" => 10, "expect_100_timeout" => 0)); 24 | $client->enqueue($request); 25 | $client->send(); 26 | dump_headers(null, $client->getResponse()->getHeaders()); 27 | }); 28 | 29 | ?> 30 | ===DONE=== 31 | --EXPECTF-- 32 | Test 33 | Accept-Ranges: bytes 34 | Content-Length: %d 35 | Etag: "%x" 36 | Last-Modified: %s 37 | X-Original-Transfer-Encoding: chunked 38 | X-Request-Content-Length: 134217728 39 | 40 | ===DONE=== 41 | -------------------------------------------------------------------------------- /tests/client027.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client cookie woes 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | configure(array("pipelining" => false, "share_cookies" => false)); 19 | 20 | $request = new http\Client\Request("GET", "http://localhost:$port?r1"); 21 | $client->enqueue($request); 22 | $client->send(); 23 | dump_responses($client, ["counter" => 1]); 24 | 25 | $client->requeue($request); 26 | $client->send(); 27 | dump_responses($client, ["counter" => 2]); 28 | $client->dequeue($request); 29 | 30 | $request = new http\Client\Request("GET", "http://localhost:$port?r2"); 31 | $client->enqueue($request); 32 | $client->send(); 33 | dump_responses($client, ["counter" => 1]); 34 | }); 35 | 36 | ?> 37 | ===DONE=== 38 | --EXPECTF-- 39 | Test 40 | Etag: "" 41 | Set-Cookie: counter=1; 42 | X-Original-Transfer-Encoding: chunked 43 | 44 | Etag: "" 45 | Set-Cookie: counter=2; 46 | X-Original-Transfer-Encoding: chunked 47 | 48 | Etag: "" 49 | Set-Cookie: counter=1; 50 | X-Original-Transfer-Encoding: chunked 51 | 52 | ===DONE=== 53 | -------------------------------------------------------------------------------- /tests/client030.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client eventloop recursion 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | once(); 18 | } 19 | } 20 | server("proxy.inc", function($port) { 21 | $client = new http\Client; 22 | $client->configure(array( 23 | "use_eventloop" => true, 24 | )); 25 | $client->attach(new test); 26 | $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) { 27 | var_dump($r->getResponseCode()); 28 | }); 29 | $client->send(); 30 | }); 31 | 32 | ?> 33 | ===DONE=== 34 | --EXPECTF-- 35 | Test 36 | int(200) 37 | ===DONE=== -------------------------------------------------------------------------------- /tests/client031.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client cookie sharing disabled 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | configure(array("share_cookies" => false)); 19 | 20 | $request = new http\Client\Request("GET", "http://localhost:$port"); 21 | $client->enqueue($request); 22 | $client->send(); 23 | dump_responses($client, ["counter" => 1]); 24 | 25 | /* requeue the previous request */ 26 | $client->requeue($request); 27 | $client->send(); 28 | dump_responses($client, ["counter" => 2]); 29 | 30 | for($i = 0; $i < 3; ++$i) { 31 | /* new requests */ 32 | $request = new http\Client\Request("GET", "http://localhost:$port"); 33 | $client->enqueue($request); 34 | $client->send(); 35 | dump_responses($client, ["counter" => 1]); 36 | } 37 | 38 | /* requeue the previous request */ 39 | $client->requeue($request); 40 | $client->send(); 41 | dump_responses($client, ["counter" => 2]); 42 | }); 43 | 44 | ?> 45 | ===DONE=== 46 | --EXPECTF-- 47 | Test 48 | Etag: "" 49 | Set-Cookie: counter=1; 50 | X-Original-Transfer-Encoding: chunked 51 | 52 | Etag: "" 53 | Set-Cookie: counter=2; 54 | X-Original-Transfer-Encoding: chunked 55 | 56 | Etag: "" 57 | Set-Cookie: counter=1; 58 | X-Original-Transfer-Encoding: chunked 59 | 60 | Etag: "" 61 | Set-Cookie: counter=1; 62 | X-Original-Transfer-Encoding: chunked 63 | 64 | Etag: "" 65 | Set-Cookie: counter=1; 66 | X-Original-Transfer-Encoding: chunked 67 | 68 | Etag: "" 69 | Set-Cookie: counter=2; 70 | X-Original-Transfer-Encoding: chunked 71 | 72 | ===DONE=== 73 | -------------------------------------------------------------------------------- /tests/client032.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client cookie sharing enabled 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | configure(array("share_cookies" => true)); 19 | 20 | $request = new http\Client\Request("GET", "http://localhost:$port"); 21 | $client->enqueue($request); 22 | $client->send(); 23 | dump_responses($client, ["counter" => 1]); 24 | 25 | /* requeue the previous request */ 26 | $client->requeue($request); 27 | $client->send(); 28 | dump_responses($client, ["counter" => 2]); 29 | 30 | for($i = 3; $i < 6; ++$i) { 31 | /* new requests */ 32 | $request = new http\Client\Request("GET", "http://localhost:$port"); 33 | $client->enqueue($request); 34 | $client->send(); 35 | dump_responses($client, ["counter" => $i]); 36 | } 37 | 38 | /* requeue the previous request */ 39 | $client->requeue($request); 40 | $client->send(); 41 | dump_responses($client, ["counter" => $i]); 42 | }); 43 | 44 | ?> 45 | ===DONE=== 46 | --EXPECTF-- 47 | Test 48 | Etag: "" 49 | Set-Cookie: counter=1; 50 | X-Original-Transfer-Encoding: chunked 51 | 52 | Etag: "" 53 | Set-Cookie: counter=2; 54 | X-Original-Transfer-Encoding: chunked 55 | 56 | Etag: "" 57 | Set-Cookie: counter=3; 58 | X-Original-Transfer-Encoding: chunked 59 | 60 | Etag: "" 61 | Set-Cookie: counter=4; 62 | X-Original-Transfer-Encoding: chunked 63 | 64 | Etag: "" 65 | Set-Cookie: counter=5; 66 | X-Original-Transfer-Encoding: chunked 67 | 68 | Etag: "" 69 | Set-Cookie: counter=6; 70 | X-Original-Transfer-Encoding: chunked 71 | 72 | ===DONE=== 73 | -------------------------------------------------------------------------------- /tests/clientrequest001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client request 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getBody()); 20 | var_dump($h === $r->getHeaders()); 21 | var_dump($u === $r->getRequestUrl()); 22 | var_dump($m === $r->getRequestMethod()); 23 | 24 | ?> 25 | Done 26 | --EXPECT-- 27 | Test 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | Done 33 | -------------------------------------------------------------------------------- /tests/clientrequest002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client request content type 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setContentType($ct = "text/plain; charset=utf-8")); 14 | var_dump($ct === $r->getContentType()); 15 | 16 | ?> 17 | Done 18 | --EXPECT-- 19 | Test 20 | bool(true) 21 | bool(true) 22 | Done 23 | -------------------------------------------------------------------------------- /tests/clientrequest003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client request query 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getQuery()); 14 | var_dump($r === $r->setQuery($q = "foo=bar")); 15 | var_dump($q === $r->getQuery()); 16 | var_dump($r === $r->addQuery("a[]=1&a[]=2")); 17 | var_dump("foo=bar&a%5B0%5D=1&a%5B1%5D=2" === $r->getQuery()); 18 | var_dump(null === $r->setQuery(null)->getQuery()); 19 | 20 | ?> 21 | Done 22 | --EXPECT-- 23 | Test 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | Done 31 | -------------------------------------------------------------------------------- /tests/clientrequest004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client request options 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setOptions($o = array("redirect"=>5, "timeout"=>5))); 14 | var_dump($o === $r->getOptions()); 15 | var_dump($r === $r->setOptions(array("timeout"=>50))); 16 | $o["timeout"] = 50; 17 | var_dump($o === $r->getOptions()); 18 | var_dump($r === $r->setSslOptions($o = array("verify_peer"=>false))); 19 | var_dump($o === $r->getSslOptions()); 20 | 21 | ?> 22 | Done 23 | --EXPECT-- 24 | Test 25 | bool(true) 26 | bool(true) 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | Done 32 | -------------------------------------------------------------------------------- /tests/clientresponse001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client response cookie 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) { 21 | var_dump($cookies->toArray()); 22 | } 23 | } 24 | }); 25 | ?> 26 | Done 27 | --EXPECTREGEX-- 28 | Test 29 | (?:array\(7\) \{\n \["cookies"\]\=\>\n array\(2\) \{\n \["foo"\]\=\>\n string\(3\) "bar"\n \["bar"\]\=\>\n string\(3\) "foo"\n \}\n \["extras"\]\=\>\n array\(0\) \{\n \}\n \["flags"\]\=\>\n int\(0\)\n \["expires"\]\=\>\n int\(\-1\)\n \["max\-age"\]\=\>\n int\(\-1\)\n \["path"\]\=\>\n string\(0\) ""\n \["domain"\]\=\>\n string\(0\) ""\n\}\n)+Done 30 | -------------------------------------------------------------------------------- /tests/clientresponse002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client response cookies 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enqueue($request)->send()->getResponse()->getCookies(0, array("comment")) as $cookies) { 21 | var_dump($cookies->toArray()); 22 | } 23 | } 24 | }); 25 | ?> 26 | Done 27 | --EXPECTREGEX-- 28 | Test 29 | (?:array\(7\) \{\n \["cookies"\]\=\>\n array\(1\) \{\n \["temp"\]\=\>\n string\(1\d\) "\d+\.\d+"\n \}\n \["extras"\]\=\>\n array\(0\) \{\n \}\n \["flags"\]\=\>\n int\(0\)\n \["expires"\]\=\>\n int\(\-1\)\n \["max\-age"\]\=\>\n int\(\-1\)\n \["path"\]\=\>\n string\(0\) ""\n \["domain"\]\=\>\n string\(0\) ""\n\}\narray\(7\) \{\n \["cookies"\]\=\>\n array\(1\) \{\n \["perm"\]\=\>\n string\(1\d\) "\d+\.\d+"\n \}\n \["extras"\]\=\>\n array\(0\) \{\n \}\n \["flags"\]\=\>\n int\(0\)\n \["expires"\]\=\>\n int\(\d+\)\n \["max\-age"\]\=\>\n int\(\-1\)\n \["path"\]\=\>\n string\(0\) ""\n \["domain"\]\=\>\n string\(0\) ""\n\}\n)+Done 30 | -------------------------------------------------------------------------------- /tests/clientresponse003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | client response transfer info 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enqueue($request)->send()->getResponse(); 21 | var_dump($response->getTransferInfo("response_code")); 22 | var_dump(count((array)$response->getTransferInfo())); 23 | } 24 | }); 25 | ?> 26 | Done 27 | --EXPECTREGEX-- 28 | Test 29 | (?:int\([1-5]\d\d\) 30 | int\(\d\d\) 31 | )+Done 32 | -------------------------------------------------------------------------------- /tests/cookie001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies empty state 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array(), 15 | "extras" => array(), 16 | "flags" => 0, 17 | "expires" => -1, 18 | "path" => "", 19 | "domain" => "", 20 | "max-age" => -1, 21 | ); 22 | var_dump($a == $c->toArray()); 23 | var_dump($a == $o->toArray()); 24 | 25 | ?> 26 | DONE 27 | --EXPECT-- 28 | Test 29 | bool(true) 30 | bool(true) 31 | DONE 32 | -------------------------------------------------------------------------------- /tests/cookie002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies expire as date 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | date.timezone=UTC 9 | --FILE-- 10 | $d->format(DateTime::RFC1123))); 15 | var_dump($d->format("U") == $c->getExpires()); 16 | 17 | ?> 18 | DONE 19 | --EXPECT-- 20 | Test 21 | bool(true) 22 | DONE 23 | -------------------------------------------------------------------------------- /tests/cookie003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies numeric keys 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | DONE 16 | --EXPECT-- 17 | Test 18 | bool(true) 19 | DONE 20 | -------------------------------------------------------------------------------- /tests/cookie004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies raw 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | DONE 16 | --EXPECT-- 17 | Test 18 | bool(true) 19 | DONE 20 | -------------------------------------------------------------------------------- /tests/cookie005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies simple data 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toArray()); 15 | foreach (array($orig, $copy) as $c) { 16 | var_dump($c->getCookie("key")); 17 | var_dump($c->getExpires()); 18 | var_dump($c->getMaxAge()); 19 | var_dump($c->getFlags()); 20 | var_dump($c->getPath()); 21 | var_dump($c->getDomain()); 22 | var_dump($c->getExtras()); 23 | var_dump($c->getCookies()); 24 | var_dump($c->toString()); 25 | var_dump( 26 | array ( 27 | "cookies" => 28 | array ( 29 | "key" => "value", 30 | ), 31 | "extras" => 32 | array ( 33 | ), 34 | "flags" => 0, 35 | "expires" => -1, 36 | "path" => "", 37 | "domain" => "", 38 | "max-age" => -1, 39 | ) == $c->toArray() 40 | ); 41 | } 42 | 43 | ?> 44 | DONE 45 | --EXPECT-- 46 | Test 47 | string(5) "value" 48 | int(-1) 49 | int(-1) 50 | int(0) 51 | NULL 52 | NULL 53 | array(0) { 54 | } 55 | array(1) { 56 | ["key"]=> 57 | string(5) "value" 58 | } 59 | string(11) "key=value; " 60 | bool(true) 61 | string(5) "value" 62 | int(-1) 63 | int(-1) 64 | int(0) 65 | NULL 66 | NULL 67 | array(0) { 68 | } 69 | array(1) { 70 | ["key"]=> 71 | string(5) "value" 72 | } 73 | string(11) "key=value; " 74 | bool(true) 75 | DONE 76 | -------------------------------------------------------------------------------- /tests/cookie006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies expire 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | date.timezone=UTC 9 | --FILE-- 10 | getCookie("this")); 15 | var_dump($c->getExpires()); 16 | 17 | $o = clone $c; 18 | $t = time(); 19 | 20 | $o->setExpires(); 21 | var_dump(-1 === $o->getExpires()); 22 | var_dump(-1 != $c->getExpires()); 23 | 24 | $o->setExpires($t); 25 | var_dump($t === $o->getExpires()); 26 | var_dump($t != $c->getExpires()); 27 | var_dump( 28 | sprintf( 29 | "this=expires; expires=%s; ", 30 | date_create("@$t") 31 | ->setTimezone(new DateTimezone("UTC")) 32 | ->format("D, d M Y H:i:s \\G\\M\\T") 33 | ) === $o->toString() 34 | ); 35 | 36 | ?> 37 | DONE 38 | --EXPECT-- 39 | Test 40 | string(7) "expires" 41 | int(1327397732) 42 | bool(true) 43 | bool(true) 44 | bool(true) 45 | bool(true) 46 | bool(true) 47 | DONE 48 | -------------------------------------------------------------------------------- /tests/cookie007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies max-age 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | date.timezone=UTC 9 | --FILE-- 10 | getCookie("this")); 15 | var_dump($c->getMaxAge()); 16 | $o = clone $c; 17 | $t = 54321; 18 | $o->setMaxAge(); 19 | var_dump($o->getMaxAge()); 20 | var_dump(-1 != $c->getMaxAge()); 21 | $o->setMaxAge($t); 22 | var_dump($o->getMaxAge()); 23 | var_dump($t != $c->getMaxAge()); 24 | var_dump($o->toString()); 25 | 26 | ?> 27 | DONE 28 | --EXPECT-- 29 | Test 30 | string(7) "max-age" 31 | int(12345) 32 | int(-1) 33 | bool(true) 34 | int(54321) 35 | bool(true) 36 | string(29) "this=max-age; max-age=54321; " 37 | DONE 38 | -------------------------------------------------------------------------------- /tests/cookie008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies path 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getCookie("this")); 13 | var_dump((string)$c); 14 | var_dump($c->getPath()); 15 | $o = clone $c; 16 | $p = "/up"; 17 | $o->setPath(); 18 | var_dump($o->getPath()); 19 | var_dump($c->getPath()); 20 | $o->setPath($p); 21 | var_dump($o->getPath()); 22 | var_dump($c->getPath()); 23 | var_dump($o->toString()); 24 | 25 | ?> 26 | DONE 27 | --EXPECT-- 28 | Test 29 | string(10) "has a path" 30 | string(33) "this=has%20a%20path; path=/down; " 31 | string(5) "/down" 32 | NULL 33 | string(5) "/down" 34 | string(3) "/up" 35 | string(5) "/down" 36 | string(31) "this=has%20a%20path; path=/up; " 37 | DONE 38 | -------------------------------------------------------------------------------- /tests/cookie009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies domain 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getCookie("this")); 13 | var_dump((string)$c); 14 | var_dump($c->getDomain()); 15 | $o = clone $c; 16 | $d = "sub.example.com"; 17 | $o->setDomain(); 18 | var_dump($o->getDomain()); 19 | var_dump($c->getDomain()); 20 | $o->setDomain($d); 21 | var_dump($o->getDomain()); 22 | var_dump($c->getDomain()); 23 | var_dump($o->toString()); 24 | 25 | ?> 26 | DONE 27 | --EXPECT-- 28 | Test 29 | string(12) "has a domain" 30 | string(44) "this=has%20a%20domain; domain=.example.com; " 31 | string(12) ".example.com" 32 | NULL 33 | string(12) ".example.com" 34 | string(15) "sub.example.com" 35 | string(12) ".example.com" 36 | string(47) "this=has%20a%20domain; domain=sub.example.com; " 37 | DONE 38 | -------------------------------------------------------------------------------- /tests/cookie010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies flags 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getFlags() & http\Cookie::SECURE)); 13 | var_dump(http\Cookie::HTTPONLY === ($c->getFlags() & http\Cookie::HTTPONLY)); 14 | $c->setFlags($c->getFlags() ^ http\Cookie::SECURE); 15 | var_dump(!($c->getFlags() & http\Cookie::SECURE)); 16 | var_dump(http\Cookie::HTTPONLY === ($c->getFlags() & http\Cookie::HTTPONLY)); 17 | $c->setFlags($c->getFlags() ^ http\Cookie::HTTPONLY); 18 | var_dump(!($c->getFlags() & http\Cookie::SECURE)); 19 | var_dump(!($c->getFlags() & http\Cookie::HTTPONLY)); 20 | var_dump("icanhas=flags; " === $c->toString()); 21 | $c->setFlags(http\Cookie::SECURE|http\Cookie::HTTPONLY); 22 | var_dump("icanhas=flags; secure; httpOnly; " === $c->toString()); 23 | ?> 24 | DONE 25 | --EXPECT-- 26 | Test 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | bool(true) 33 | bool(true) 34 | bool(true) 35 | DONE 36 | -------------------------------------------------------------------------------- /tests/cookie011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies extras 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "v1", "c2"=>"v2") === $c->getCookies()); 12 | var_dump(array("e0"=>"1", "e2"=>"2") === $c->getExtras()); 13 | $c->addExtra("e1", 1); 14 | $c->setExtra("e0"); 15 | $c->setExtra("e3", 123); 16 | var_dump("123" === $c->getExtra("e3")); 17 | $c->setExtra("e3"); 18 | var_dump(array("e2"=>"2", "e1"=>"1") === $c->getExtras()); 19 | var_dump("c1=v1; c2=v2; e2=2; e1=1; " === $c->toString()); 20 | $c->addExtras(array("e3"=>3, "e4"=>4)); 21 | var_dump(array("e2"=>"2", "e1"=>"1", "e3"=>"3", "e4"=>"4") === $c->getExtras()); 22 | var_dump("c1=v1; c2=v2; e2=2; e1=1; e3=3; e4=4; " === $c->toString()); 23 | $c->setExtras(array("e"=>"x")); 24 | var_dump(array("e"=>"x") === $c->getExtras()); 25 | var_dump("c1=v1; c2=v2; e=x; " === $c->toString()); 26 | $c->setExtras(); 27 | var_dump(array() === $c->getExtras()); 28 | var_dump("c1=v1; c2=v2; " === $c->toString()); 29 | 30 | ?> 31 | DONE 32 | --EXPECT-- 33 | Test 34 | bool(true) 35 | bool(true) 36 | bool(true) 37 | bool(true) 38 | bool(true) 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | bool(true) 43 | bool(true) 44 | bool(true) 45 | DONE 46 | -------------------------------------------------------------------------------- /tests/cookie012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cookies cookies 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "v1", "c2"=>"v2") === $c->getExtras()); 12 | var_dump(array("e0"=>"1", "e2"=>"2") === $c->getCookies()); 13 | $c->addCookie("e1", 1); 14 | $c->setCookie("e0"); 15 | $c->setCookie("e3", 123); 16 | var_dump("123" === $c->getCookie("e3")); 17 | $c->setCookie("e3"); 18 | var_dump(array("e2"=>"2", "e1"=>"1") === $c->getCookies()); 19 | var_dump("e2=2; e1=1; c1=v1; c2=v2; " === $c->toString()); 20 | $c->addCookies(array("e3"=>3, "e4"=>4)); 21 | var_dump(array("e2"=>"2", "e1"=>"1", "e3"=>"3", "e4"=>"4") === $c->getCookies()); 22 | var_dump("e2=2; e1=1; e3=3; e4=4; c1=v1; c2=v2; " === $c->toString()); 23 | $c->setCookies(array("e"=>"x")); 24 | var_dump(array("e"=>"x") === $c->getCookies()); 25 | var_dump("e=x; c1=v1; c2=v2; " === $c->toString()); 26 | $c->setCookies(); 27 | var_dump(array() === $c->getCookies()); 28 | var_dump("c1=v1; c2=v2; " === $c->toString()); 29 | 30 | ?> 31 | DONE 32 | --EXPECT-- 33 | Test 34 | bool(true) 35 | bool(true) 36 | bool(true) 37 | bool(true) 38 | bool(true) 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | bool(true) 43 | bool(true) 44 | bool(true) 45 | DONE 46 | -------------------------------------------------------------------------------- /tests/data/bug71719.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m6w6/ext-http/c5c376e36b93de2e08ab2c1b7f5a3a559007eaf9/tests/data/bug71719.bin -------------------------------------------------------------------------------- /tests/data/message_r_content_range.txt: -------------------------------------------------------------------------------- 1 | PUT / HTTP/1.1 2 | User-Agent: PECL_HTTP/2.3.0dev PHP/5.6.6-dev libcurl/7.41.0-DEV 3 | Host: localhost:8000 4 | Accept: */* 5 | Expect: 100-continue 6 | Content-Length: 3 7 | Content-Range: bytes 1-2/3 8 | 9 | 23 -------------------------------------------------------------------------------- /tests/data/message_rr_empty.txt: -------------------------------------------------------------------------------- 1 | GET /default/empty.txt HTTP/1.1 2 | Host: localhost 3 | Connection: close 4 | 5 | HTTP/1.1 200 OK 6 | Date: Wed, 25 Aug 2010 12:11:44 GMT 7 | Server: Apache/2.2.16 (Unix) 8 | mod_ssl/2.2.16 9 | OpenSSL/1.0.0a 10 | mod_fastcgi/2.4.6 11 | Last-Modified: Wed, 28 Apr 2010 10:54:37 GMT 12 | ETag: "2002a-0-48549d615a35c" 13 | Accept-Ranges: bytes 14 | Content-Length: 0 15 | Vary: Accept-Encoding 16 | Connection: close 17 | Content-Type: text/plain 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/data/message_rr_empty_chunked.txt: -------------------------------------------------------------------------------- 1 | GET /default/empty.php HTTP/1.1 2 | Connection: close 3 | Host: localhost 4 | 5 | HTTP/1.1 200 OK 6 | Date: Thu, 26 Aug 2010 11:41:02 GMT 7 | Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6 8 | X-Powered-By: PHP/5.3.3 9 | Vary: Accept-Encoding 10 | Connection: close 11 | Transfer-Encoding: chunked 12 | Content-Type: text/html 13 | 14 | 0 15 | 16 | -------------------------------------------------------------------------------- /tests/data/message_rr_empty_gzip.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m6w6/ext-http/c5c376e36b93de2e08ab2c1b7f5a3a559007eaf9/tests/data/message_rr_empty_gzip.txt -------------------------------------------------------------------------------- /tests/data/message_rr_helloworld_chunked.txt: -------------------------------------------------------------------------------- 1 | GET /cgi-bin/chunked.sh HTTP/1.1 2 | Host: localhost 3 | Connection: close 4 | 5 | HTTP/1.1 200 OK 6 | Date: Thu, 26 Aug 2010 12:51:28 GMT 7 | Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/1.0.0a mod_fastcgi/2.4.6 8 | Vary: Accept-Encoding 9 | Connection: close 10 | Transfer-Encoding: chunked 11 | Content-Type: text/plain 12 | 13 | 5 14 | Hello 15 | 2 16 | , 17 | 7 18 | World! 19 | 20 | 0 21 | 22 | -------------------------------------------------------------------------------- /tests/data/urls.txt: -------------------------------------------------------------------------------- 1 | http://www.microsoft.com 2 | http://www.opensource.org 3 | http://www.google.com 4 | http://www.yahoo.com 5 | http://www.ibm.com 6 | http://www.mysql.com 7 | http://www.oracle.com 8 | http://www.ripe.net 9 | http://www.iana.org 10 | http://www.amazon.com 11 | http://www.netcraft.com 12 | http://www.heise.de 13 | http://www.chip.de 14 | http://www.ca.com 15 | http://www.cnet.com 16 | http://www.news.com 17 | http://www.cnn.com 18 | http://www.wikipedia.org 19 | http://www.dell.com 20 | http://www.hp.com 21 | http://www.cert.org 22 | http://www.mit.edu 23 | http://www.nist.gov 24 | http://www.ebay.com 25 | http://www.postgresql.org 26 | http://www.uefa.com 27 | http://www.ieee.org 28 | http://www.apple.com 29 | http://www.sony.com 30 | http://www.symantec.com 31 | http://www.zdnet.com 32 | http://www.fujitsu.com 33 | http://www.supermicro.com 34 | http://www.hotmail.com 35 | http://www.ecma.com 36 | http://www.bbc.co.uk 37 | http://news.google.com 38 | http://www.foxnews.com 39 | http://www.msn.com 40 | http://www.wired.com 41 | http://www.sky.com 42 | http://www.usatoday.com 43 | http://www.cbs.com 44 | http://www.nbc.com 45 | http://slashdot.org 46 | http://www.bloglines.com 47 | http://www.freecode.org 48 | http://www.newslink.org 49 | http://www.un.org 50 | -------------------------------------------------------------------------------- /tests/encstream001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream chunked static 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 22 | DONE 23 | --EXPECT-- 24 | Test 25 | bool(true) 26 | DONE 27 | 28 | -------------------------------------------------------------------------------- /tests/encstream002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream chunked not encoded 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | DONE 16 | --EXPECTF-- 17 | Test 18 | 19 | Notice: http\Encoding\Stream\Dechunk::decode(): Data does not seem to be chunked encoded in %s on line %d 20 | bool(true) 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/encstream003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream chunked error 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 18 | DONE 19 | --EXPECTF-- 20 | Test 21 | 22 | Warning: http\Encoding\Stream\Dechunk::decode(): Expected LF at pos 8 of 20 but got 0x74 in %s on line %d 23 | 24 | Warning: http\Encoding\Stream\Dechunk::decode(): Truncated message: chunk size 190 exceeds remaining data size 11 at pos 9 of 20 in %s on line %d 25 | string(14) "is ter than 26 | 1 27 | " 28 | 29 | Warning: http\Encoding\Stream\Dechunk::decode(): Expected CRLF at pos 10 of 24 but got 0x74 0x74 in %s on line %d 30 | 31 | Warning: http\Encoding\Stream\Dechunk::decode(): Truncated message: chunk size 190 exceeds remaining data size 12 at pos 12 of 24 in %s on line %d 32 | string(15) "is er than 33 | 1 34 | " 35 | 36 | Warning: http\Encoding\Stream\Dechunk::decode(): Expected chunk size at pos 6 of 27 but got trash in %s on line %d 37 | bool(false) 38 | DONE 39 | -------------------------------------------------------------------------------- /tests/encstream004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream chunked flush 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | $line) { 15 | $dech = clone $dech; 16 | if ($i % 2) { 17 | $data .= $dech->update(sprintf("%lx\r\n%s\r\n", strlen($line), $line)); 18 | } else { 19 | $data .= $dech->update(sprintf("%lx\r\n", strlen($line))); 20 | $data .= $dech->flush(); 21 | $data .= $dech->update($line); 22 | $data .= $dech->flush(); 23 | $data .= $dech->update("\r\n"); 24 | } 25 | $dech->flush(); 26 | $dech->done() and printf("uh-oh done() reported true!\n"); 27 | } 28 | $data .= $dech->update("0\r\n"); 29 | var_dump($dech->done()); 30 | $data .= $dech->finish(); 31 | var_dump(implode("", $file) === $data); 32 | ?> 33 | DONE 34 | --EXPECT-- 35 | Test 36 | bool(true) 37 | bool(true) 38 | DONE 39 | -------------------------------------------------------------------------------- /tests/encstream005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream zlib static 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 35 | DONE 36 | --EXPECT-- 37 | Test 38 | bool(true) 39 | bool(true) 40 | bool(true) 41 | DONE 42 | -------------------------------------------------------------------------------- /tests/encstream006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream zlib auto flush 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | update($defl->update($data))) { 19 | printf("uh-oh »%s« != »%s«\n", $data, $d); 20 | } 21 | } 22 | } 23 | 24 | echo $infl->update($defl->finish()); 25 | echo $infl->finish(); 26 | ?> 27 | DONE 28 | --EXPECT-- 29 | Test 30 | DONE 31 | -------------------------------------------------------------------------------- /tests/encstream007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream zlib without flush 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | update($line))) { 19 | foreach(str_split($temp) as $byte) { 20 | $data .= $infl->update($byte); 21 | } 22 | } 23 | } 24 | if (strlen($temp = $defl->finish())) { 25 | $data .= $infl->update($temp); 26 | } 27 | $data .= $infl->finish(); 28 | var_dump(implode("", $file) === $data); 29 | ?> 30 | DONE 31 | --EXPECT-- 32 | Test 33 | bool(true) 34 | DONE 35 | -------------------------------------------------------------------------------- /tests/encstream008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream zlib with explicit flush 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | flush(); 17 | if (strlen($temp = $defl->update($line))) { 18 | $data .= $infl->update($temp); 19 | $data .= $infl->flush(); 20 | } 21 | if (strlen($temp = $defl->flush())) { 22 | $data .= $infl->update($temp); 23 | $data .= $infl->flush(); 24 | } 25 | $defl->done() or printf("uh-oh stream's not done yet!\n"); 26 | } 27 | if (strlen($temp = $defl->finish())) { 28 | $data .= $infl->update($temp); 29 | } 30 | var_dump($defl->done()); 31 | $data .= $infl->finish(); 32 | var_dump($infl->done()); 33 | var_dump(implode("", $file) === $data); 34 | 35 | ?> 36 | DONE 37 | --EXPECT-- 38 | Test 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | DONE 43 | -------------------------------------------------------------------------------- /tests/encstream009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream zlib error 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 14 | DONE 15 | --EXPECTF-- 16 | Test 17 | 18 | Warning: http\Encoding\Stream\Inflate::decode(): Could not inflate data: data error in %s on line %d 19 | bool(false) 20 | DONE 21 | -------------------------------------------------------------------------------- /tests/encstream015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream brotli static 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 36 | DONE 37 | --EXPECT-- 38 | Test 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | DONE 43 | -------------------------------------------------------------------------------- /tests/encstream016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream brotli auto flush 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | update($defl->update($data))) { 19 | printf("uh-oh »%s« != »%s«\n", $data, $d); 20 | } 21 | } 22 | } 23 | 24 | echo $infl->update($defl->finish()); 25 | echo $infl->finish(); 26 | 27 | var_dump($infl->done(), $defl->done()); 28 | ?> 29 | DONE 30 | --EXPECT-- 31 | Test 32 | bool(true) 33 | bool(true) 34 | DONE 35 | -------------------------------------------------------------------------------- /tests/encstream017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream brotli without flush 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | update($line))) { 18 | foreach(str_split($temp) as $byte) { 19 | $data .= $infl->update($byte); 20 | } 21 | } 22 | } 23 | if (strlen($temp = $defl->finish())) { 24 | $data .= $infl->update($temp); 25 | } 26 | $data .= $infl->finish(); 27 | var_dump(implode("", $file) === $data); 28 | ?> 29 | DONE 30 | --EXPECT-- 31 | Test 32 | bool(true) 33 | DONE 34 | -------------------------------------------------------------------------------- /tests/encstream018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream brotli with explicit flush 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | flush(); 18 | if (strlen($temp = $enc->update($line))) { 19 | $data .= $dec->update($temp); 20 | $data .= $dec->flush(); 21 | } 22 | if (strlen($temp = $enc->flush())) { 23 | $data .= $dec->update($temp); 24 | $data .= $dec->flush(); 25 | } 26 | } 27 | if (strlen($temp = $enc->finish())) { 28 | $data .= $dec->update($temp); 29 | } 30 | var_dump($enc->done()); 31 | $data .= $dec->finish(); 32 | var_dump($dec->done()); 33 | var_dump(implode("", $file) === $data); 34 | 35 | ?> 36 | DONE 37 | --EXPECT-- 38 | Test 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | DONE 43 | -------------------------------------------------------------------------------- /tests/encstream019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | encoding stream brotli error 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 15 | DONE 16 | --EXPECTF-- 17 | Test 18 | 19 | Warning: http\Encoding\Stream\Debrotli::decode(): Could not brotli decode data: %s in %s on line %d 20 | bool(false) 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/envrequestbody001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request body 3 | --SKIPIF-- 4 | 5 | --PUT-- 6 | Content-Type: skip/me 7 | foo 8 | --FILE-- 9 | 12 | DONE 13 | --EXPECT-- 14 | string(3) "foo" 15 | DONE 16 | -------------------------------------------------------------------------------- /tests/envrequestcookie001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request cookie 3 | --SKIPIF-- 4 | 7 | --COOKIE-- 8 | foo=bar;bar=123 9 | --FILE-- 10 | getCookie()->toArray()); 15 | var_dump($r->getCookie("foo", "s")); 16 | var_dump($r->getCookie("bar", "i")); 17 | var_dump($r->getCookie("baz", "b", true)); 18 | 19 | ?> 20 | DONE 21 | --EXPECT-- 22 | Test 23 | array(2) { 24 | ["foo"]=> 25 | string(3) "bar" 26 | ["bar"]=> 27 | string(3) "123" 28 | } 29 | string(3) "bar" 30 | int(123) 31 | bool(true) 32 | DONE 33 | -------------------------------------------------------------------------------- /tests/envrequestfiles001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request grabbing $_FILES 3 | --SKIPIF-- 4 | 5 | --POST_RAW-- 6 | Content-Type: multipart/form-data;boundary=--123 7 | 8 | ----123 9 | Content-Disposition: form-data;filename="foo.bar" 10 | 11 | foo 12 | bar 13 | 14 | ----123 15 | Content-Disposition: form-data;filename="bar.foo" 16 | 17 | bar 18 | foo 19 | 20 | ----123-- 21 | --FILE-- 22 | getFiles(); 27 | 28 | foreach ($_FILES as $i => $file) { 29 | foreach (array("name","type","size","error","file") as $key) { 30 | if ($file[$key == "file" ? "tmp_name" : $key] != $f[$i][$key]) { 31 | printf("%d.%s differs: '%s' != '%s'\n", $i, $key, $f[$i][$key], $file[$key]); 32 | } 33 | } 34 | } 35 | 36 | ?> 37 | DONE 38 | --EXPECT-- 39 | TEST 40 | DONE 41 | -------------------------------------------------------------------------------- /tests/envrequestfiles002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request grabbing $_FILES from array 3 | --SKIPIF-- 4 | 5 | --POST_RAW-- 6 | Content-Type: multipart/form-data;boundary=--123 7 | 8 | ----123 9 | Content-Disposition: form-data;filename=file1;name=file[] 10 | 11 | first 12 | ----123 13 | Content-Disposition: form-data;filename=file2;name=file[] 14 | 15 | second 16 | ----123 17 | Content-Disposition: form-data;filename=file3;name=file[] 18 | 19 | third 20 | ----123-- 21 | --FILE-- 22 | $data) { 29 | foreach ($data["tmp_name"] as $i => $file) { 30 | $f[$name][$i] = array( 31 | "file" => $file, 32 | "name" => $data["name"][$i], 33 | "size" => $data["size"][$i], 34 | "type" => $data["type"][$i], 35 | "error"=> $data["error"][$i] 36 | ); 37 | } 38 | } 39 | 40 | var_dump($f == $r->getFiles()); 41 | 42 | ?> 43 | DONE 44 | --EXPECT-- 45 | TEST 46 | bool(true) 47 | DONE 48 | -------------------------------------------------------------------------------- /tests/envrequestform.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request form 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | a=b&b=c&r[]=1&r[]=2 7 | --FILE-- 8 | getForm()); 13 | printf("%s\n", $r->getForm("b", "s", null, true)); 14 | printf("%s\n", $r->getForm("x", "s", "nooo")); 15 | printf("%s\n", $r->getForm()); 16 | ?> 17 | DONE 18 | --EXPECT-- 19 | TEST 20 | a=b&b=c&r%5B0%5D=1&r%5B1%5D=2 21 | c 22 | nooo 23 | a=b&r%5B0%5D=1&r%5B1%5D=2 24 | DONE 25 | -------------------------------------------------------------------------------- /tests/envrequestheader001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request header 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | a=b 7 | --ENV-- 8 | HTTP_HOST=foo.bar 9 | HTTP_ACCEPT=*/* 10 | --FILE-- 11 | 20 | --EXPECTF-- 21 | NULL 22 | string(%d) "foo.bar" 23 | string(%d) "application/x-www-form-urlencoded" 24 | array(4) { 25 | ["Accept"]=> 26 | string(3) "*/*" 27 | ["Content-Length"]=> 28 | string(1) "3" 29 | ["Content-Type"]=> 30 | string(33) "application/x-www-form-urlencoded" 31 | ["Host"]=> 32 | string(7) "foo.bar" 33 | } 34 | -------------------------------------------------------------------------------- /tests/envrequestquery.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env request query 3 | --SKIPIF-- 4 | 5 | --GET-- 6 | a=b&b=c&r[]=1&r[]=2 7 | --FILE-- 8 | getQuery()); 13 | printf("%s\n", $r->getQuery("b", "s", null, true)); 14 | printf("%s\n", $r->getQuery("x", "s", "nooo")); 15 | printf("%s\n", $r->getQuery()); 16 | ?> 17 | DONE 18 | --EXPECT-- 19 | TEST 20 | a=b&b=c&r%5B0%5D=1&r%5B1%5D=2 21 | c 22 | nooo 23 | a=b&r%5B0%5D=1&r%5B1%5D=2 24 | DONE 25 | -------------------------------------------------------------------------------- /tests/envreset001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env reset 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | a=b 7 | --ENV-- 8 | HTTP_HOST=foo.bar 9 | HTTP_ACCEPT=*/* 10 | --FILE-- 11 | 35 | ==DONE== 36 | --EXPECTF-- 37 | NULL 38 | string(%d) "foo.bar" 39 | string(%d) "application/x-www-form-urlencoded" 40 | array(4) { 41 | ["Accept"]=> 42 | string(3) "*/*" 43 | ["Content-Length"]=> 44 | string(1) "3" 45 | ["Content-Type"]=> 46 | string(33) "application/x-www-form-urlencoded" 47 | ["Host"]=> 48 | string(7) "foo.bar" 49 | } 50 | NULL 51 | string(%d) "foo.bar" 52 | string(%d) "yesyes" 53 | NULL 54 | string(%d) "application/x-www-form-urlencoded" 55 | array(4) { 56 | ["Accept"]=> 57 | string(3) "*/*" 58 | ["Content-Length"]=> 59 | string(1) "3" 60 | ["Content-Type"]=> 61 | string(33) "application/x-www-form-urlencoded" 62 | ["Nono"]=> 63 | string(6) "yesyes" 64 | } 65 | ==DONE== 66 | -------------------------------------------------------------------------------- /tests/envresponse001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response message 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | a=b 7 | --ENV-- 8 | HTTP_ACCEPT_ENCODING=gzip 9 | --FILE-- 10 | setHeader("foo","bar"); 14 | $r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP); 15 | $r->setBody(new http\message\Body(fopen(__FILE__,"r"))); 16 | $r->send(); 17 | 18 | --EXPECTHEADERS-- 19 | Foo: bar 20 | Content-Encoding: gzip 21 | Vary: Accept-Encoding 22 | --EXPECTREGEX-- 23 | ^\x1f\x8b\x08.+ 24 | -------------------------------------------------------------------------------- /tests/envresponse002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response cache negative 3 | --SKIPIF-- 4 | 5 | --GET-- 6 | a=b 7 | --ENV-- 8 | HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT 9 | HTTP_IF_NONE_MATCH=0000-00-0000 10 | --FILE-- 11 | setBody(new http\Message\Body(fopen(__FILE__,"rb"))); 14 | $r->setEtag("abc"); 15 | $r->setLastModified(1234567891); 16 | $r->send(); 17 | ?> 18 | --EXPECTHEADERS-- 19 | ETag: "abc" 20 | Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT 21 | --EXPECT-- 22 | setBody(new http\Message\Body(fopen(__FILE__,"rb"))); 25 | $r->setEtag("abc"); 26 | $r->setLastModified(1234567891); 27 | $r->send(); 28 | ?> 29 | -------------------------------------------------------------------------------- /tests/envresponse003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response ranges 3 | --SKIPIF-- 4 | 5 | --ENV-- 6 | HTTP_RANGE=bytes=2-4 7 | --GET-- 8 | a=b 9 | --FILE-- 10 | setContentType("text/plain"); 14 | $r->setContentDisposition( 15 | array("attachment" => array(array("filename" => basename(__FILE__)))) 16 | ); 17 | $r->setBody(new http\Message\Body(fopen(__FILE__, "rb"))); 18 | $r->send(); 19 | 20 | ?> 21 | --EXPECTHEADERS-- 22 | Content-Range: bytes 2-4/248 23 | --EXPECTF-- 24 | php 25 | -------------------------------------------------------------------------------- /tests/envresponse004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response callback 3 | --SKIPIF-- 4 | 8 | --GET-- 9 | dummy=1 10 | --FILE-- 11 | setCacheControl("public,must-revalidate,max-age=0"); 15 | $r->setThrottleRate(1, 0.1); 16 | ob_start($r); 17 | 18 | echo "foo"; 19 | echo "bar"; 20 | 21 | ob_end_flush(); 22 | $r->send(); 23 | ?> 24 | --EXPECTHEADERS-- 25 | Accept-Ranges: bytes 26 | Cache-Control: public,must-revalidate,max-age=0 27 | ETag: "9ef61f95" 28 | --EXPECTF-- 29 | foobar 30 | -------------------------------------------------------------------------------- /tests/envresponse005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response cache positive 3 | --SKIPIF-- 4 | 5 | --GET-- 6 | a=b 7 | --ENV-- 8 | HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:32 GMT 9 | --FILE-- 10 | setBody(new http\Message\Body(fopen(__FILE__,"rb"))); 13 | $r->setEtag("abc"); 14 | $r->setLastModified(1234567891); 15 | $r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n"); 16 | $r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached"); 17 | $r->send(); 18 | ?> 19 | --EXPECTHEADERS-- 20 | HTTP/1.1 304 Not Modified 21 | ETag: "abc" 22 | Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT 23 | --EXPECT-- 24 | -------------------------------------------------------------------------------- /tests/envresponse006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response stream 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | addHeader("foo", array("bar","baz")); 15 | $r->getBody()->append("foo"); 16 | 17 | $r->send($f); 18 | 19 | rewind($f); 20 | var_dump(stream_get_contents($f)); 21 | ?> 22 | Done 23 | --EXPECT-- 24 | Test 25 | string(115) "HTTP/1.1 200 OK 26 | Accept-Ranges: bytes 27 | Foo: bar, baz 28 | ETag: "8c736521" 29 | Transfer-Encoding: chunked 30 | 31 | 3 32 | foo 33 | 0 34 | 35 | " 36 | Done 37 | -------------------------------------------------------------------------------- /tests/envresponse007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response env request 3 | --SKIPIF-- 4 | 7 | --GET-- 8 | dummy=1 9 | --FILE-- 10 | setHeader("Range", "bytes=2-4"); 18 | 19 | $res = new http\Env\Response; 20 | $res->setEnvRequest($req); 21 | $res->setContentType("text/plain"); 22 | $res->getBody()->append("012345679"); 23 | $res->send($tmp); 24 | 25 | rewind($tmp); 26 | var_dump(stream_get_contents($tmp)); 27 | 28 | ?> 29 | Done 30 | --EXPECTF-- 31 | Test 32 | string(%d) "HTTP/1.1 206 Partial Content%c 33 | Accept-Ranges: bytes%c 34 | X-Powered-By: %s%c 35 | Content-Type: text/plain%c 36 | Content-Range: bytes 2-4/9%c 37 | Transfer-Encoding: chunked%c 38 | %c 39 | 3%c 40 | 234%c 41 | 0%c 42 | %c 43 | " 44 | Done 45 | -------------------------------------------------------------------------------- /tests/envresponse008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response stream message 3 | --SKIPIF-- 4 | 5 | --ENV-- 6 | HTTP_ACCEPT_ENCODING=gzip 7 | --FILE-- 8 | setHeader("foo","bar"); 14 | $r->setContentEncoding(http\env\Response::CONTENT_ENCODING_GZIP); 15 | $r->setBody(new http\message\Body(fopen(__FILE__,"r"))); 16 | $r->send($f); 17 | 18 | rewind($f); 19 | var_dump(stream_get_contents($f)); 20 | 21 | ?> 22 | --EXPECTREGEX-- 23 | string\(\d+\) "HTTP\/1\.1 200 OK 24 | Accept-Ranges: bytes 25 | Foo: bar 26 | Content-Encoding: gzip 27 | Vary: Accept-Encoding 28 | ETag: "\w+-\w+-\w+" 29 | Last-Modified: \w+, \d+ \w+ \d{4} \d\d:\d\d:\d\d GMT 30 | Transfer-Encoding: chunked 31 | 32 | d0 33 | \x1f\x8b\x08.+ 34 | 0 35 | 36 | " 37 | -------------------------------------------------------------------------------- /tests/envresponse009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response stream cache negative 3 | --SKIPIF-- 4 | 5 | --GET-- 6 | a=b 7 | --ENV-- 8 | HTTP_IF_MODIFIED_SINCE=Fri, 13 Feb 2009 23:31:30 GMT 9 | HTTP_IF_NONE_MATCH=0000-00-0000 10 | --FILE-- 11 | setBody(new http\Message\Body(fopen(__FILE__,"rb"))); 15 | $r->setEtag("abc"); 16 | $r->setLastModified(1234567891); 17 | $r->send($f); 18 | rewind($f); 19 | var_dump(stream_get_contents($f)); 20 | ?> 21 | --EXPECTF-- 22 | string(%d) "HTTP/1.1 200 OK%c 23 | Accept-Ranges: bytes%c 24 | X-Powered-By: %s%c 25 | ETag: "abc"%c 26 | Last-Modified: %s%c 27 | Transfer-Encoding: chunked%c 28 | %c 29 | e1%c 30 | setBody(new http\Message\Body(fopen(__FILE__,"rb"))); 34 | $r->setEtag("abc"); 35 | $r->setLastModified(1234567891); 36 | $r->send($f); 37 | rewind($f); 38 | var_dump(stream_get_contents($f)); 39 | ?> 40 | %c 41 | 0%c 42 | %c 43 | " 44 | 45 | -------------------------------------------------------------------------------- /tests/envresponse010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response stream ranges 3 | --SKIPIF-- 4 | 5 | --ENV-- 6 | HTTP_RANGE=bytes=2-4 7 | --GET-- 8 | a=b 9 | --FILE-- 10 | setContentType("text/plain"); 14 | $r->setContentDisposition( 15 | array("attachment" => array(array("filename" => basename(__FILE__)))) 16 | ); 17 | $r->setBody(new http\Message\Body(fopen(__FILE__, "rb"))); 18 | $r->send($f); 19 | rewind($f); 20 | var_dump(stream_get_contents($f)); 21 | ?> 22 | --EXPECTF-- 23 | string(%i) "HTTP/1.1 206 Partial Content%c 24 | Accept-Ranges: bytes%c 25 | X-Powered-By: PHP/%s%c 26 | Content-Type: text/plain%c 27 | Content-Range: bytes 2-4/311%c 28 | Transfer-Encoding: chunked%c 29 | %c 30 | 3%c 31 | php%c 32 | 0%c 33 | %c 34 | " 35 | -------------------------------------------------------------------------------- /tests/envresponse011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response cache positive with env message 3 | --SKIPIF-- 4 | 5 | --GET-- 6 | dummy=1 7 | --FILE-- 8 | setHeader("If-Modified-Since", "Fri, 13 Feb 2009 23:31:32 GMT"); 11 | $r = new http\Env\Response; 12 | $r->setEnvRequest($e); 13 | $r->setBody(new http\Message\Body(fopen(__FILE__,"rb"))); 14 | $r->setEtag("abc"); 15 | $r->setLastModified(1234567891); 16 | $r->isCachedByEtag("If-None-Match") and die("Huh? etag? really?\n"); 17 | $r->isCachedByLastModified("If-Modified-Since") or die("yep, I should be cached"); 18 | $r->send(); 19 | ?> 20 | --EXPECTHEADERS-- 21 | HTTP/1.1 304 Not Modified 22 | ETag: "abc" 23 | Last-Modified: Fri, 13 Feb 2009 23:31:31 GMT 24 | --EXPECT-- 25 | -------------------------------------------------------------------------------- /tests/envresponse012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response content disposition 3 | --SKIPIF-- 4 | 7 | --GET-- 8 | dummy=1 9 | --FILE-- 10 | setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__)))); 14 | $r->setBody(new http\Message\Body(fopen(__FILE__,"r"))); 15 | $r->send(); 16 | 17 | ?> 18 | --EXPECTHEADERS-- 19 | Content-Disposition: attachment;filename=envresponse012.php 20 | --EXPECT-- 21 | setContentDisposition(array("attachment"=>array("filename"=>basename(__FILE__)))); 25 | $r->setBody(new http\Message\Body(fopen(__FILE__,"r"))); 26 | $r->send(); 27 | 28 | ?> 29 | 30 | -------------------------------------------------------------------------------- /tests/envresponse013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response deflate 3 | --SKIPIF-- 4 | 7 | --GET-- 8 | dummy=1 9 | --FILE-- 10 | setHeader("Accept-Encoding", "deflate"); 14 | 15 | $res = new http\Env\Response; 16 | $res->setCacheControl("public, max-age=3600"); 17 | $res->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP); 18 | $res->getBody()->append("foobar"); 19 | 20 | $res->setEnvRequest($req); 21 | $res->send(); 22 | ?> 23 | --EXPECTHEADERS-- 24 | Content-Encoding: deflate 25 | Vary: Accept-Encoding 26 | Cache-Control: public, max-age=3600 27 | --EXPECTREGEX-- 28 | ^\x78\x9c.+ 29 | 30 | -------------------------------------------------------------------------------- /tests/envresponse014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response invalid ranges 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setHeader("Range", "bytes=321-123,123-0"); 12 | $res = new http\Env\Response; 13 | $res->getBody()->append("foobar"); 14 | $res->setEnvRequest($req); 15 | $res->send($f); 16 | rewind($f); 17 | var_dump(stream_get_contents($f)); 18 | --EXPECTF-- 19 | string(129) "HTTP/1.1 416 Requested Range Not Satisfiable 20 | Accept-Ranges: bytes 21 | Content-Range: bytes */6 22 | Transfer-Encoding: chunked 23 | 24 | 0 25 | 26 | " 27 | 28 | -------------------------------------------------------------------------------- /tests/envresponse015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response send replaced body using multiple ob_start 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getBody(); 17 | $r->setBody(new http\Message\Body); 18 | 19 | ob_start($r); 20 | echo "foo: $b\n"; 21 | ob_end_flush(); 22 | 23 | $f = fopen("php://memory", "r+"); 24 | 25 | $r->send($f); 26 | 27 | fseek($f, 0, SEEK_SET); 28 | echo stream_get_contents($f); 29 | 30 | ?> 31 | --EXPECT-- 32 | HTTP/1.1 200 OK 33 | Accept-Ranges: bytes 34 | ETag: "fc8305a1" 35 | Transfer-Encoding: chunked 36 | 37 | 9 38 | foo: bar 39 | 40 | 0 41 | 42 | -------------------------------------------------------------------------------- /tests/envresponse016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response send failure 3 | --SKIPIF-- 4 | 7 | --XFAIL-- 8 | stream filters leak since 8.2 9 | --FILE-- 10 | getBody()->append(str_repeat("a", 16*1024*4)); 27 | $s = fopen("php://temp", "w"); 28 | stream_filter_append($s, "closer"); 29 | var_dump($r->send($s)); 30 | ?> 31 | DONE 32 | --EXPECTF-- 33 | Test 34 | 35 | Warning: http\Env\Response::send(): Failed to send response body in %s on line %d 36 | bool(false) 37 | DONE 38 | -------------------------------------------------------------------------------- /tests/envresponse017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response stream: no chunked transfer encoding for CONNECTs 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setRequestMethod("CONNECT"); 13 | $req->setRequestUrl(array("host"=>"www.example.com", "port"=>80)); 14 | 15 | echo $req; 16 | 17 | $res = new http\Env\Response; 18 | $res->setEnvRequest($req); 19 | $res->send(STDOUT); 20 | 21 | ?> 22 | ===DONE=== 23 | --EXPECTF-- 24 | Test 25 | CONNECT www.example.com:80 HTTP/1.1 26 | HTTP/1.1 200 OK 27 | 28 | ===DONE=== 29 | -------------------------------------------------------------------------------- /tests/envresponse018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response don't generate stat based etag for temp stream 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | append("1234567890\n"); 13 | 14 | $r = new http\Env\Response; 15 | $r->setBody($b); 16 | $r->send(STDOUT); 17 | 18 | ?> 19 | ===DONE=== 20 | --EXPECTF-- 21 | Test 22 | HTTP/1.1 200 OK 23 | Accept-Ranges: bytes 24 | ETag: "%x" 25 | Last-Modified: %s 26 | Transfer-Encoding: chunked 27 | 28 | b 29 | 1234567890 30 | 31 | 0 32 | 33 | ===DONE=== 34 | -------------------------------------------------------------------------------- /tests/envresponsebody001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response body 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | output_buffering=1 9 | --FILE-- 10 | getBody()); 14 | ?> 15 | Done 16 | --EXPECTF-- 17 | Test 18 | string(5) "Test 19 | " 20 | Done 21 | -------------------------------------------------------------------------------- /tests/envresponsebody002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response body error 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | output_buffering=1 9 | --FILE-- 10 | getBody()); 16 | } catch (http\Exception $e) { 17 | echo $e->getMessage(),"\n"; 18 | } 19 | ?> 20 | Done 21 | --EXPECTF-- 22 | Test 23 | http\Env\Response::__construct(): Could not fetch response body, output has already been sent at %senvresponsebody002.php:3 24 | Done 25 | -------------------------------------------------------------------------------- /tests/envresponsecodes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response codes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 21 | Done 22 | --EXPECT-- 23 | Test 24 | array(0) { 25 | } 26 | Done 27 | -------------------------------------------------------------------------------- /tests/envresponsecookie001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response cookie 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | addCookie("foo","bar"); 13 | $c->setMaxAge(60); 14 | $r->setCookie($c); 15 | $r->setCookie("baz"); 16 | $r->setCookie(123); 17 | $r->send(STDOUT); 18 | 19 | ?> 20 | --EXPECT-- 21 | HTTP/1.1 200 OK 22 | Set-Cookie: foo=bar; max-age=60; 23 | Set-Cookie: baz=1; 24 | Set-Cookie: 123=1; 25 | ETag: "" 26 | Transfer-Encoding: chunked 27 | 28 | 0 29 | 30 | -------------------------------------------------------------------------------- /tests/envresponseheader001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | env response header 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | %s 29 | [Foo] => bar 30 | [More] => Array 31 | ( 32 | [0] => than 33 | [1] => what's 34 | [2] => good 35 | ) 36 | 37 | [Content-Type] => %s 38 | ) 39 | Created 40 | -------------------------------------------------------------------------------- /tests/envresponseranges001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ranges 3 | --SKIPIF-- 4 | 7 | --GET-- 8 | a=b 9 | --ENV-- 10 | HTTP_RANGE=bytes=-3,000-001,1-1,0-0,100- 11 | --FILE-- 12 | setBody(new http\Message\Body(fopen(__FILE__, "rb"))); 16 | $r->send(); 17 | 18 | ?> 19 | --EXPECTF-- 20 | --%s%c 21 | Content-Type: application/octet-stream%c 22 | Content-Range: bytes 107-109/110%c 23 | %c 24 | ?> 25 | %c 26 | --%s%c 27 | Content-Type: application/octet-stream%c 28 | Content-Range: bytes 0-1/110%c 29 | %c 30 | 48 | %c 49 | --%s-- -------------------------------------------------------------------------------- /tests/etag001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | etags with hash 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | append("Hello, my old fellow."); 12 | foreach (["md5", "sha1", "sha256"] as $algo) { 13 | if (strncmp($algo, "sha3-", 5) && strncmp($algo, "sha512/", 7) && strcmp($algo, "crc32c")) { 14 | ini_set("http.etag.mode", $algo); 15 | printf("%10s: %s\n", 16 | $algo, 17 | $body->etag() 18 | ); 19 | } 20 | } 21 | ?> 22 | DONE 23 | --EXPECT-- 24 | md5: 6ce3cc8f3861fb7fd0d77739f11cd29c 25 | sha1: ad84012eabe27a61762a97138d9d2623f4f1a7a9 26 | sha256: ed9ecfe5c76d51179c3c1065916fdb8d94aee05577f187bd763cdc962bba1f42 27 | DONE 28 | -------------------------------------------------------------------------------- /tests/filterbrotli.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | brotli filter 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 30 | DONE 31 | --EXPECT-- 32 | DONE 33 | -------------------------------------------------------------------------------- /tests/filterchunked.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | chunked filter 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 27 | DONE 28 | --EXPECT-- 29 | DONE 30 | -------------------------------------------------------------------------------- /tests/filterzlib.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | zlib filter 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 27 | DONE 28 | --EXPECT-- 29 | DONE 30 | -------------------------------------------------------------------------------- /tests/gh-issue11.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | crash when query string has nested array keys 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 17 | ===DONE=== 18 | --EXPECT-- 19 | Test 20 | a%5B0%5D%5B0%5D=x&a%5B1%5D%5B0%5D=x 21 | ===DONE=== 22 | -------------------------------------------------------------------------------- /tests/gh-issue12.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | crash with bad url passed to http\Message::setRequestUrl() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setRequestUrl($url); 19 | printf("OK: %s\n", $url); 20 | } catch (Exception $e) { 21 | printf("%s\n", $e->getMessage()); 22 | } 23 | } 24 | 25 | ?> 26 | ===DONE=== 27 | --EXPECT-- 28 | Test 29 | http\Message::setRequestUrl(): Failed to parse host; unexpected '.' at pos 0 in '.foo.bar' 30 | http\Message::setRequestUrl(): Failed to parse host; unexpected '.' at pos 4 in 'foo..bar' 31 | OK: http://foo.bar. 32 | ===DONE=== 33 | -------------------------------------------------------------------------------- /tests/gh-issue42.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | URL barfs on punycode 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 12 | ===DONE=== 13 | --EXPECT-- 14 | Test 15 | http://www.xn--kln-sna.de/ 16 | ===DONE=== 17 | -------------------------------------------------------------------------------- /tests/gh-issue47.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Null pointer deref in sanitize_value 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | mod($urls[1]); 18 | 19 | echo $url1; 20 | 21 | ?> 22 | 23 | ===DONE=== 24 | --EXPECTF-- 25 | Test 26 | http://%s/ 27 | ===DONE=== 28 | -------------------------------------------------------------------------------- /tests/gh-issue50.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | segfault with Client::setDebug and Client::dequeue() 3 | --SKIPIF-- 4 | 9 | --INI-- 10 | zend.exception_ignore_args=off 11 | --FILE-- 12 | enqueue(new http\Client\Request("GET", "http://example.com")); 17 | 18 | $c->setDebug(function(http\Client $c, http\Client\Request $r, $type, $data) { 19 | if ($type & http\Client::DEBUG_HEADER) { 20 | $c->dequeue($r); 21 | } 22 | }); 23 | 24 | try { 25 | $c->send(); 26 | } catch (Exception $e) { 27 | echo $e; 28 | } 29 | 30 | ?> 31 | 32 | ===DONE=== 33 | --EXPECTF-- 34 | Test 35 | http\Exception\RuntimeException: http\Client::dequeue(): Could not dequeue request while executing callbacks in %sgh-issue50.php:9 36 | Stack trace: 37 | #0 %sgh-issue50.php(9): http\Client->dequeue(Object(http\Client\Request)) 38 | #1 [internal function]: {closur%s}(Object(http\Client), Object(http\Client\Request), 18, 'GET / HTTP/1.1%s...') 39 | #2 %sgh-issue50.php(14): http\Client->send() 40 | #3 {main} 41 | ===DONE=== 42 | -------------------------------------------------------------------------------- /tests/gh-issue6.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url - unsafe characters 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | query; 12 | echo "\n"; 13 | $url = new http\Url("?id={\$id}"); 14 | echo $url->query; 15 | echo "\n"; 16 | 17 | ?> 18 | ===DONE=== 19 | --EXPECT-- 20 | Test 21 | __utma=1152894289.1017686999.9107388726.1439222726.1494721726.1&__utmb=115739289.1.10.1437388726&__utmc=115883619&__utmx=-&__utmz=115111289.14310476.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)&__utmv=-&__utmk=112678937 22 | id={$id} 23 | ===DONE=== 24 | -------------------------------------------------------------------------------- /tests/gh-issue63.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | gh issue #63: Url::mod() breaks query strings containing plus-notation spaces in the input URL 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 'bar']; 16 | $parts['query'] = new QueryString($query); 17 | echo (new Url($url, null, Url::STDFLAGS))->mod($parts)->toString(); 18 | 19 | ?> 20 | 21 | ===DONE=== 22 | --EXPECTF-- 23 | Test 24 | http://example.com/?param=has%20spaces&foo=bar 25 | ===DONE=== 26 | -------------------------------------------------------------------------------- /tests/header001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header string 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 16 | Done 17 | --EXPECT-- 18 | Test 19 | bool(true) 20 | Done 21 | -------------------------------------------------------------------------------- /tests/header002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header numeric 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 16 | Done 17 | --EXPECT-- 18 | Test 19 | bool(true) 20 | Done 21 | -------------------------------------------------------------------------------- /tests/header003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header serialize 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 18 | Done 19 | --EXPECT-- 20 | Test 21 | bool(true) 22 | bool(true) 23 | Done 24 | -------------------------------------------------------------------------------- /tests/header004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header match 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | match("gzip", http\Header::MATCH_WORD)); 14 | var_dump($ae->match("gzip", http\Header::MATCH_WORD|http\Header::MATCH_CASE)); 15 | var_dump($ae->match("gzip", http\Header::MATCH_STRICT)); 16 | var_dump($ae->match("deflate", http\Header::MATCH_WORD)); 17 | var_dump($ae->match("deflate", http\Header::MATCH_WORD|http\Header::MATCH_CASE)); 18 | var_dump($ae->match("deflate", http\Header::MATCH_STRICT)); 19 | var_dump($ae->match("zip", http\Header::MATCH_WORD)); 20 | var_dump($ae->match("gzip", http\Header::MATCH_FULL)); 21 | 22 | ?> 23 | Done 24 | --EXPECT-- 25 | Test 26 | bool(true) 27 | bool(true) 28 | bool(false) 29 | bool(true) 30 | bool(true) 31 | bool(false) 32 | bool(false) 33 | bool(false) 34 | Done 35 | -------------------------------------------------------------------------------- /tests/header005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header negotiation 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | negotiate(array("text/plain","text/html"))); 16 | var_dump("text/html" === $a->negotiate(array("text/plain","text/html"), $rs)); 17 | var_dump(array("text/html"=>0.99, "text/plain"=>0.5) === array_map("r", $rs)); 18 | var_dump("text/plain" === $a->negotiate(array("foo/bar", "text/plain"), $rs)); 19 | var_dump(array("text/plain"=>0.5) === array_map("r", $rs)); 20 | var_dump("foo/bar" === $a->negotiate(array("foo/bar"), $rs)); 21 | var_dump(array() === $rs); 22 | 23 | ?> 24 | Done 25 | --EXPECT-- 26 | Test 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | bool(true) 33 | bool(true) 34 | Done 35 | -------------------------------------------------------------------------------- /tests/header006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header parsing 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "bar","Bar"=>"foo") === http\Header::parse($header)); 14 | 15 | $headers = http\Header::parse($header, "http\\Header"); 16 | var_dump(2 === count($headers)); 17 | var_dump(2 === array_reduce($headers, function($count, $header) { 18 | return $count + ($header instanceof http\Header); 19 | }, 0)); 20 | ?> 21 | Done 22 | --EXPECT-- 23 | Test 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | Done 28 | -------------------------------------------------------------------------------- /tests/header007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header parse error 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 16 | Done 17 | --EXPECTF-- 18 | Test 19 | 20 | Warning: http\Header::parse(): Failed to parse headers: unexpected end of line at pos 4 of 'wass\nup' in %s on line %d 21 | Done 22 | -------------------------------------------------------------------------------- /tests/header008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array("value" => true, "arguments" => array()), 16 | "must-revalidate" => array("value" => true, "arguments" => array()), 17 | "max-age" => array("value" => "0", "arguments" => array()), 18 | ) === $header->getParams()->params 19 | ); 20 | 21 | ?> 22 | Done 23 | --EXPECT-- 24 | Test 25 | bool(true) 26 | Done 27 | -------------------------------------------------------------------------------- /tests/header009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params w/ args 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array("value" => "bar", "arguments" => array()), 16 | "bar" => array("value" => "bis", "arguments" => array("bis" => "where")) 17 | ) === $header->getParams(".", "where", "is")->params 18 | ); 19 | 20 | ?> 21 | Done 22 | --EXPECT-- 23 | Test 24 | bool(true) 25 | Done 26 | -------------------------------------------------------------------------------- /tests/headerparser001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header parser 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "FAILURE",0=>"START","KEY","VALUE","VALUE_EX","HEADER_DONE","DONE"); 21 | $parser = new http\Header\Parser; 22 | do { 23 | $state = $parser->parse($part = array_shift($headers), 24 | $headers ? 0 : http\Header\Parser::CLEANUP, 25 | $result); 26 | printf("%2\$-32s | %1\$s\n", $states[$state], addcslashes($part, "\r\n\t\0")); 27 | } while ($headers && $state !== http\Header\Parser::STATE_FAILURE); 28 | 29 | var_dump($result); 30 | 31 | ?> 32 | ===DONE=== 33 | --EXPECT-- 34 | Test 35 | One: | VALUE 36 | header\n | VALUE_EX 37 | Two: header\n\tlines\n | VALUE_EX 38 | Three | KEY 39 | : header\n lines\n here\n | VALUE_EX 40 | More: than one header\n | VALUE_EX 41 | More: | VALUE 42 | than: | VALUE 43 | you: | VALUE 44 | expect\n | VALUE_EX 45 | \n | DONE 46 | array(4) { 47 | ["One"]=> 48 | string(6) "header" 49 | ["Two"]=> 50 | string(12) "header lines" 51 | ["Three"]=> 52 | string(17) "header lines here" 53 | ["More"]=> 54 | array(2) { 55 | [0]=> 56 | string(15) "than one header" 57 | [1]=> 58 | string(17) "than: you: expect" 59 | } 60 | } 61 | ===DONE=== 62 | -------------------------------------------------------------------------------- /tests/headerparser002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header parser errors 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | parse($header, http\Header\Parser::CLEANUP, $parsed), $parsed); 24 | } 25 | ?> 26 | ===DONE=== 27 | --EXPECTF-- 28 | Test 29 | 30 | Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 2 of 'Na\000me' in %sheaderparser002.php on line %d 31 | int(-1) 32 | array(0) { 33 | } 34 | 35 | Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected end of line at pos 2 of 'Na\nme: value' in %sheaderparser002.php on line %d 36 | int(-1) 37 | array(0) { 38 | } 39 | 40 | Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 0 of '\000value' in %sheaderparser002.php on line %d 41 | int(-1) 42 | array(0) { 43 | } 44 | 45 | Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected end of input at pos 5 of 'value' in %sheaderparser002.php on line %d 46 | int(-1) 47 | array(0) { 48 | } 49 | 50 | Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 3 of 'val\000ue' in %sheaderparser002.php on line %d 51 | int(-1) 52 | array(0) { 53 | } 54 | 55 | Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 5 of 'value\000' in %sheaderparser002.php on line %d 56 | int(-1) 57 | array(0) { 58 | } 59 | ===DONE=== -------------------------------------------------------------------------------- /tests/headerparser003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header parser with nonblocking stream 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | stream($socket[0], 0, $hdrs); 25 | fwrite($socket[1], $line); 26 | var_dump($parser->getState()); 27 | var_dump($parser->stream($socket[0], 0, $hdrs)); 28 | } 29 | 30 | var_dump($hdrs); 31 | 32 | ?> 33 | DONE 34 | --EXPECT-- 35 | Test 36 | int(0) 37 | int(1) 38 | int(1) 39 | int(2) 40 | int(2) 41 | int(3) 42 | int(3) 43 | int(1) 44 | int(1) 45 | int(3) 46 | int(3) 47 | int(5) 48 | array(2) { 49 | ["Host"]=> 50 | string(9) "localhost" 51 | ["Content-Length"]=> 52 | string(1) "3" 53 | } 54 | DONE 55 | -------------------------------------------------------------------------------- /tests/helper/cookie.inc: -------------------------------------------------------------------------------- 1 | getHeader("cookie")); 8 | $response = new http\Env\Response; 9 | $response->setCookie($cookies->setCookie("counter", $cookies->getCookie("counter")+1)); 10 | $response->send($client); 11 | }); 12 | -------------------------------------------------------------------------------- /tests/helper/cookie1.inc: -------------------------------------------------------------------------------- 1 | setCookie("foo", "bar"); 9 | $cookies->setCookie("bar", "foo"); 10 | $response = new http\Env\Response; 11 | $response->setCookie($cookies); 12 | $response->send($client); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/helper/cookie2.inc: -------------------------------------------------------------------------------- 1 | getHeader("Cookie")); 9 | $new_cookies = new http\Cookie; 10 | $new_cookies->setCookie("temp", $old_cookies->getCookie("temp") ?: microtime(true)); 11 | $response->setCookie($new_cookies); 12 | $new_cookies = new http\Cookie; 13 | $new_cookies->setCookie("perm", $old_cookies->getCookie("perm") ?: microtime(true)); 14 | $new_cookies->setExpires(time()+3600); 15 | $response->setCookie($new_cookies); 16 | $response->send($client); 17 | }); 18 | -------------------------------------------------------------------------------- /tests/helper/dump.inc: -------------------------------------------------------------------------------- 1 | $val) { 9 | fprintf($stream, "%s: %s\n", $key, $val); 10 | } 11 | fprintf($stream, "\n"); 12 | } 13 | 14 | function dump_message($stream, http\Message $msg, $parent = false) { 15 | if (!is_resource($stream)) { 16 | $stream = fopen("php://output", "w"); 17 | } 18 | fprintf($stream, "%s\n", $msg->getInfo()); 19 | dump_headers($stream, $msg->getHeaders()); 20 | $msg->getBody()->toStream($stream); 21 | 22 | if ($parent && ($msg = $msg->getParentMessage())) { 23 | dump_message($stream, $msg, true); 24 | } 25 | } 26 | 27 | function dump_responses($client, array $expect_cookie = []) { 28 | while (($r = $client->getResponse())) { 29 | dump_headers(null, $r->getHeaders()); 30 | if ($expect_cookie) { 31 | $got_cookies = array_merge(...array_map(function($c) { 32 | return $c->getCookies(); 33 | }, $r->getCookies())); 34 | if ($expect_cookie != $got_cookies) { 35 | var_dump($expect_cookie, $got_cookies); 36 | echo $r->toString(true); 37 | } 38 | } 39 | } 40 | 41 | } 42 | ?> 43 | -------------------------------------------------------------------------------- /tests/helper/env.inc: -------------------------------------------------------------------------------- 1 | setEnvRequest($request); 10 | $response->setContentEncoding(http\Env\Response::CONTENT_ENCODING_GZIP); 11 | $response->setHeader("X-Request-Content-Length", $request->getBody()->stat("size")); 12 | ob_start($response); 13 | if ($request->isMultipart()) { 14 | $files = []; 15 | foreach ($request->splitMultipartBody() as $part) { 16 | $cd = $part->getHeader("Content-Disposition", http\Header::class)->getParams(); 17 | foreach ($cd->params as $key => $val) { 18 | if ($key === "form-data" && $val["value"] === true) { 19 | if (isset($val["arguments"]["filename"])) { 20 | $files[$val["arguments"]["name"]] = [ 21 | "name" => $val["arguments"]["filename"], 22 | "type" => $part->getHeader("Content-Type"), 23 | "size" => $part->getBody()->stat("s"), 24 | ]; 25 | } 26 | } 27 | } 28 | print_r($files); 29 | } 30 | } else { 31 | if (($c = $request->getHeader("Cookie"))) { 32 | print_r((new http\Cookie($c))->getCookies()); 33 | } 34 | if ($request->getBody()->stat("s")) { 35 | var_dump($request->getBody()->toString()); 36 | } 37 | } 38 | ob_end_flush(); 39 | $response->send($client); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/helper/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTTP2 6 | 7 | 8 | Nothing to see here. 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/helper/http2.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDNzCCAh+gAwIBAgIJAKOw1awbt7aIMA0GCSqGSIb3DQEBCwUAMDIxCzAJBgNV 3 | BAYTAkFUMQ8wDQYDVQQKDAZQSFAgUUExEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0x 4 | NTAyMTIxMjQ2NTRaFw0xNzExMDcxMjQ2NTRaMDIxCzAJBgNVBAYTAkFUMQ8wDQYD 5 | VQQKDAZQSFAgUUExEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEB 6 | BQADggEPADCCAQoCggEBAMxa+A6xEKQOYme55nQyu0qpvvGB4c4wGBNa6X6YAEzE 7 | Hc19Nbix02UZWQgHM1dmBhbVDW3stO42CQmcViIKfAy5R1A9UZjUcn9nQpaxL/sp 8 | 9LrrCANyljISXS40QcBvhCzmcUvDWBRhVTGjV+QTaYmmaM+8hJJJM6W7ByIP22Zv 9 | jHoAnzTx9sjs+OMyWmjYT9pWv6aE+u5iSC8bn3B0GgtfPwoPqDF8ePxIMBpmtbk7 10 | JqXFzHxTVywkypnsF34XK94QjpvRcFGSg/Dc1TopJG2Wfq8hxwtoKerSlL5tyKy0 11 | ZrltxCiLkfVZixwNZEqkg7jPSUvLS299mBrwy+ikmr8CAwEAAaNQME4wHQYDVR0O 12 | BBYEFDiHynoXXjMChfYhc1k7TNtU8ey0MB8GA1UdIwQYMBaAFDiHynoXXjMChfYh 13 | c1k7TNtU8ey0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGD9GERC 14 | uJv+oHfMwkNkDV5ZB4F+SQPzXVxDx+rJm1aGJs9PcwPNiV5GweXbvgcnvRAL4h8h 15 | uv3MLQPgVOq0iqp1QPFCoUXxbYYjYzi9FVbR/154sg0uWEHElU2e3fSjcinNRfXD 16 | 12232k6HNwSeeZUFQqn2fuk+cae5BsYT8GfsyMq5EfPtG2d8IG+Ji4eEOJeKu4gl 17 | Y33yQnHhw6QKbx8vWaDpZK8qtpapCtLrTtw/nRhX5YV6kMGK+htQUK1etV2O0VQQ 18 | OtDrhOWWaDxQULsHIvCMgTTnZqNQD+Xz4MBm3PGEGi/QUsrEaSQYppb8xxQKZU4X 19 | MyTh7rO5TdNSXmo= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /tests/helper/http2.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEAzFr4DrEQpA5iZ7nmdDK7Sqm+8YHhzjAYE1rpfpgATMQdzX01 3 | uLHTZRlZCAczV2YGFtUNbey07jYJCZxWIgp8DLlHUD1RmNRyf2dClrEv+yn0uusI 4 | A3KWMhJdLjRBwG+ELOZxS8NYFGFVMaNX5BNpiaZoz7yEkkkzpbsHIg/bZm+MegCf 5 | NPH2yOz44zJaaNhP2la/poT67mJILxufcHQaC18/Cg+oMXx4/EgwGma1uTsmpcXM 6 | fFNXLCTKmewXfhcr3hCOm9FwUZKD8NzVOikkbZZ+ryHHC2gp6tKUvm3IrLRmuW3E 7 | KIuR9VmLHA1kSqSDuM9JS8tLb32YGvDL6KSavwIDAQABAoIBAQCzUdAB9FYJ36Vy 8 | J6qVpD69EZ7ABZzDdWhq84eY0oDQ2/ba7lhJraE2QbviU481zgzh1CponyFVNo1P 9 | paPfUxvvflWZj3Ueiq2+JjpESU81MmfR7ZOmktJBNeQWOzzHRBPT4pLgTJXprE85 10 | s3/YX0BozWGDiIU8aIetkiR8OzXm97+BrJWiPFl733dGnHvfpHAZu/PwKZc2+8ft 11 | CnQw4GHRhTBWCVNj29HLwm+CA66zQqiAXItgijWMKzs+9ciPn+aCsCnZDNF+o1zs 12 | 4pWt60CtIJQtD3r3rSRy7nBaCKcTrr/JU3FvwqKdunuUBUsuYeSaMBokW67kpVzS 13 | dO9L9p6BAoGBAP+pvcAd8qfC1WIrn9vka3aK25ulbYSCae3YaWmABc93INJPBMvO 14 | GrcUuaLKiQC1oou+E64vGyJ9MeEFwxh2zbvU75a9ezeKAajgaq92ciMX2QqREh0N 15 | IntNOc4w7eB6BK8NpaDXNvTtxNWMvlYyhVN0M7FVQRmYJfCJdnTZAkzvAoGBAMyf 16 | 6rvWuc/wmIcAtBVe+jIeQ69EJJ/Idcjk0JUm6lFECAAraPpsCglha+wTHWWRQZ9u 17 | pPqBnb7QPjevU+3bZHnMvGoEzd5F4Rw74J+p5EZeMUJpuKmon7Ekzemcb0DV+qX9 18 | NorB781D2Z0MG9SCptKyKpN5TPHTjGz4BB3mLC8xAoGAdq99/ynn9ClmleRameI4 19 | YRelS2RIqzM/qcLFbMyZ5e4PtpIoT9SmYkekxgXwA/xOMUFUMZB8sE4eUbAzGbBN 20 | Yd1APGJKSUYv7w3/eOUrp07y2wzts77dOxBmvWnJhGQguINFWJ2QTbPzpI9p7OoX 21 | Kt7PAIvrZM5VDo1CCIyVnNECgYEAgLmpZXlzcwicK3GZ2EfjhVvcoIlxsMLetf6b 22 | 6PiON4lgrxqf88m7lqMezWhI+fgjHDTyvFSF89/1A/rcBaoazzSo4tka2VWEg8p3 23 | SHoMDOh8fJcdgD2AGGRa1TeAFX2HLJzajvfp72tbnpxbdZircah7eEK60PaQRIzR 24 | qi1+ZkECgYEAi7GkO7Ey98DppLnt7567veQoEj0u8ixTlCyJ4V278nHR5+6eAZP5 25 | PfdZVC3MtKGLnxrrPTVUy5wU0hR6Gk9EVDmrAF8TgJdnZFlBK7X23eWZ0q4qO/eO 26 | 3xIi+UrNwLag8BjYOr32nP/i+F+TLikgRIFR4oiZjk867+ofkTXmNFA= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /tests/helper/pipeline.inc: -------------------------------------------------------------------------------- 1 | setEnvRequest($msg) 8 | ->setHeader("X-Req", $msg->getRequestUrl()) 9 | ->send($client); 10 | } 11 | 12 | serve(function($client) { 13 | $R = array(STDIN); $W = $E = array(); 14 | if (!stream_select($R, $W, $E, 10, 0)) { 15 | logger("Client %d timed out", (int) $client); 16 | return; 17 | } 18 | $count = trim(fgets(STDIN)); 19 | logger("Expecting %d messages from client %d", $count, (int) $client); 20 | /* the peek message */ 21 | respond($client, new http\Message($client, false)); 22 | logger("Handled the peek request of client %d", (int) $client); 23 | /* pipelined messages */ 24 | $req = array(); 25 | for ($i=0; $i < $count; ++ $i) { 26 | $req[] = $m = new http\Message($client, false); 27 | logger("Read request no. %d from client %d (%s)", $i+1, (int) $client, $m->getRequestUrl()); 28 | } 29 | foreach ($req as $i => $msg) { 30 | respond($client, $msg); 31 | logger("Sent response no. %d to client %d", $i+1, (int) $client); 32 | } 33 | }); 34 | -------------------------------------------------------------------------------- /tests/helper/proxy.inc: -------------------------------------------------------------------------------- 1 | = 7.48 does not send Proxy-Connection anymore */ 11 | if ($request->getHeader("Proxy-Connection") 12 | || $request->getRequestMethod() === "CONNECT") { 13 | $response = new http\Env\Response; 14 | $response->setEnvRequest($request); 15 | $response->send($client); 16 | 17 | /* soak up the request following the connect */ 18 | new http\Message($client, false); 19 | } 20 | 21 | /* return the initial message as response body */ 22 | $response = new http\Env\Response; 23 | $response->setHeader("X-Request-Content-Length", $request->getBody()->stat("size")); 24 | /* avoid OOM with $response->getBody()->append($request); */ 25 | dump_message($response->getBody()->getResource(), $request); 26 | $response->send($client); 27 | }); 28 | -------------------------------------------------------------------------------- /tests/helper/upload.inc: -------------------------------------------------------------------------------- 1 | getHeader("Expect") === "100-continue") { 10 | $response = new http\Env\Response; 11 | $response->setEnvRequest($request); 12 | $response->setResponseCode(100); 13 | $response->send($client); 14 | } 15 | 16 | /* return the initial message as response body */ 17 | $response = new http\Env\Response; 18 | /* avoid OOM with $response->getBody()->append($request); */ 19 | dump_message($response->getBody()->getResource(), $request); 20 | $response->send($client); 21 | }); 22 | -------------------------------------------------------------------------------- /tests/info002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | invalid HTTP info 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | zend.exception_ignore_args=off 9 | --FILE-- 10 | 34 | ===DONE=== 35 | --EXPECTF-- 36 | Test 37 | http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\057' at pos 4 of 'HTTP/1.1 99 Apples in my Basket' in %sinfo002.php:%d 38 | Stack trace: 39 | #0 %sinfo002.php(%d): http\Message->__construct('HTTP/1.1 99 App...') 40 | #1 %sinfo002.php(%d): {%s}() 41 | #2 %sinfo002.php(%d): trap(Object(Closure)) 42 | #3 {main} 43 | http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 7 of 'CONNECT HTTP/1.1' in %sinfo002.php:%d 44 | Stack trace: 45 | #0 %sinfo002.php(%d): http\Message->__construct('CONNECT HTTP/1....') 46 | #1 %sinfo002.php(%d): {%s}() 47 | #2 %sinfo002.php(%d): trap(Object(Closure)) 48 | #3 {main} 49 | HTTP/1.1 200 50 | CONNECT www.example.org:80 HTTP/1.1 51 | ===DONE=== 52 | -------------------------------------------------------------------------------- /tests/message004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message reversal 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toString(true); 18 | echo "===\n"; 19 | echo newHttpMessage($s)->reverse()->toString(true); 20 | 21 | $m = newHttpMessage($s); 22 | $r = $m->reverse(); 23 | unset($m); 24 | var_dump($r->count()); 25 | echo $r->toString(true); 26 | 27 | ?> 28 | DONE 29 | --EXPECTF-- 30 | GET /first HTTP/1.1 31 | 32 | HTTP/1.1 200 Ok-first 33 | 34 | GET /second HTTP/1.1 35 | 36 | HTTP/1.1 200 Ok-second 37 | 38 | GET /third HTTP/1.1 39 | 40 | HTTP/1.1 200 Ok-third 41 | 42 | === 43 | HTTP/1.1 200 Ok-third 44 | 45 | GET /third HTTP/1.1 46 | 47 | HTTP/1.1 200 Ok-second 48 | 49 | GET /second HTTP/1.1 50 | 51 | HTTP/1.1 200 Ok-first 52 | 53 | GET /first HTTP/1.1 54 | 55 | int(6) 56 | HTTP/1.1 200 Ok-third 57 | 58 | GET /third HTTP/1.1 59 | 60 | HTTP/1.1 200 Ok-second 61 | 62 | GET /second HTTP/1.1 63 | 64 | HTTP/1.1 200 Ok-first 65 | 66 | GET /first HTTP/1.1 67 | 68 | DONE 69 | 70 | -------------------------------------------------------------------------------- /tests/message005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message cloning 3 | --SKIPIF-- 4 | setType(http\Message::TYPE_REQUEST); 17 | $cpy->setHeaders(array("Numbers" => array(1,2,3,4.5))); 18 | 19 | echo $msg; 20 | echo "\n===\n"; 21 | echo $cpy; 22 | 23 | ?> 24 | DONE 25 | --EXPECTF-- 26 | HTTP/1.1 200 Ok 27 | String: foobar 28 | 29 | === 30 | UNKNOWN / HTTP/1.1 31 | Numbers: 1 32 | Numbers: 2 33 | Numbers: 3 34 | Numbers: 4.5 35 | DONE 36 | -------------------------------------------------------------------------------- /tests/message007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message to stream 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | addHeader("Content-Type", "text/plain"); 14 | $m->getBody()->append("this\nis\nthe\ntext"); 15 | 16 | $f = tmpfile(); 17 | $m->toStream($f); 18 | rewind($f); 19 | var_dump((string) $m === stream_get_contents($f)); 20 | fclose($f); 21 | 22 | ?> 23 | Done 24 | --EXPECT-- 25 | Test 26 | bool(true) 27 | Done 28 | -------------------------------------------------------------------------------- /tests/message008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message to callback 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | addHeader("Content-Type", "text/plain"); 14 | $m->getBody()->append("this\nis\nthe\ntext"); 15 | 16 | $d = new http\Encoding\Stream\Deflate; 17 | $s = ""; 18 | $m->toCallback(function ($m, $data) use ($d, &$s) { 19 | $s.=$d->update($data); 20 | }); 21 | $s.=$d->finish(); 22 | var_dump($m->toString() === http\Encoding\Stream\Inflate::decode($s)); 23 | 24 | ?> 25 | Done 26 | --EXPECT-- 27 | Test 28 | bool(true) 29 | Done 30 | -------------------------------------------------------------------------------- /tests/message010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | append("foo"); 15 | $m->addBody($body); 16 | $body = new http\Message\Body; 17 | $body->append("bar"); 18 | $m->addBody($body); 19 | var_dump("foobar" === (string) $m->getBody()); 20 | 21 | ?> 22 | Done 23 | --EXPECT-- 24 | Test 25 | bool(true) 26 | Done 27 | -------------------------------------------------------------------------------- /tests/message012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message part 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | addHeader("Content-Type", "text/plain"); 14 | $p->getBody()->append("data"); 15 | 16 | $m = new http\Message("HTTP/1.1 200"); 17 | $m->getBody()->addPart($p); 18 | echo $m; 19 | 20 | ?> 21 | Done 22 | --EXPECTF-- 23 | Test 24 | HTTP/1.1 200 25 | Content-Length: %d 26 | Content-Type: multipart/form-data; boundary="%x.%x" 27 | 28 | --%x.%x 29 | Content-Type: text/plain 30 | Content-Length: 4 31 | 32 | data 33 | --%x.%x-- 34 | Done 35 | -------------------------------------------------------------------------------- /tests/message013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message detach 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | detach(); 20 | var_dump(3 === count($m)); 21 | var_dump(1 === count($d)); 22 | 23 | var_dump("HTTP/1.1 302 Found\r\n\r\n" === $d->toString(true)); 24 | 25 | ?> 26 | Done 27 | --EXPECTF-- 28 | Test 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | bool(true) 33 | Done 34 | -------------------------------------------------------------------------------- /tests/message014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message prepend 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | prepend($p); 18 | $p = $m; 19 | } 20 | 21 | var_dump( 22 | "HTTP/1.1 200\r\n\r\n". 23 | "HTTP/1.1 201\r\n\r\n". 24 | "HTTP/1.1 202\r\n\r\n". 25 | "HTTP/1.1 203\r\n\r\n". 26 | "HTTP/1.1 204\r\n\r\n". 27 | "HTTP/1.1 205\r\n\r\n". 28 | "HTTP/1.1 206\r\n\r\n". 29 | "HTTP/1.1 207\r\n\r\n". 30 | "HTTP/1.1 208\r\n\r\n" === 31 | $m->toString(true) 32 | ); 33 | 34 | ?> 35 | Done 36 | --EXPECTF-- 37 | Test 38 | bool(true) 39 | Done 40 | -------------------------------------------------------------------------------- /tests/message015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message errors 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setRequestUrl("/foo"); 15 | } catch (http\Exception $e) { 16 | echo $e->getMessage(),"\n"; 17 | } 18 | $m->setType(http\Message::TYPE_REQUEST); 19 | try { 20 | $m->setRequestUrl(""); 21 | } catch (http\Exception $e) { 22 | echo $e->getMessage(),"\n"; 23 | } 24 | 25 | $m = new http\Message; 26 | try { 27 | $m->getParentMessage(); 28 | die("unreached"); 29 | } catch (http\Exception $e) { 30 | echo $e->getMessage(),"\n"; 31 | } 32 | 33 | $m = new http\Message("HTTP/1.1 200\r\nHTTP/1.1 201"); 34 | try { 35 | $m->prepend($m->getParentMessage()); 36 | die("unreached"); 37 | } catch (http\Exception $e) { 38 | echo $e->getMessage(),"\n"; 39 | } 40 | 41 | ?> 42 | Done 43 | --EXPECTF-- 44 | Test 45 | http\Message is not of type request 46 | Cannot set http\Message's request url to an empty string 47 | http\Message has no parent message 48 | Cannot prepend a message located within the same message chain 49 | Done 50 | -------------------------------------------------------------------------------- /tests/message016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message content range 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 12 | ===DONE=== 13 | --EXPECT-- 14 | Test 15 | PUT / HTTP/1.1 16 | User-Agent: PECL_HTTP/2.3.0dev PHP/5.6.6-dev libcurl/7.41.0-DEV 17 | Host: localhost:8000 18 | Accept: */* 19 | Expect: 100-continue 20 | Content-Length: 3 21 | Content-Range: bytes 1-2/3 22 | X-Original-Content-Length: 3 23 | 24 | 23===DONE=== 25 | -------------------------------------------------------------------------------- /tests/messagebody001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body stat 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | stat("size")); 14 | var_dump(filemtime(__FILE__) === $file->stat("mtime")); 15 | var_dump(fileatime(__FILE__) === $file->stat("atime")); 16 | var_dump(filectime(__FILE__) === $file->stat("ctime")); 17 | var_dump( 18 | (object) array( 19 | "size" => 0, 20 | "mtime" => 0, 21 | "atime" => 0, 22 | "ctime" => 0, 23 | ) == $temp->stat() 24 | ); 25 | ?> 26 | DONE 27 | --EXPECT-- 28 | Test 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | bool(true) 33 | bool(true) 34 | DONE 35 | -------------------------------------------------------------------------------- /tests/messagebody002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body append 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | append("yes"); 13 | 14 | var_dump((string) $temp); 15 | 16 | ?> 17 | DONE 18 | --EXPECT-- 19 | Test 20 | string(3) "yes" 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/messagebody003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body append error 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | zend.exception_ignore_args=off 9 | --FILE-- 10 | append("nope"); 16 | } catch (Exception $e) { 17 | echo $e, "\n"; 18 | } 19 | 20 | ?> 21 | DONE 22 | --EXPECTF-- 23 | Test 24 | http\Exception\RuntimeException: http\Message\Body::append(): Failed to append 4 bytes to body; wrote 0 in %s:%d 25 | Stack trace: 26 | #0 %s(%d): http\Message\Body->append('nope') 27 | #1 {main} 28 | DONE 29 | -------------------------------------------------------------------------------- /tests/messagebody004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body add form 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | addForm( 13 | array( 14 | "foo" => "bar", 15 | "more" => array( 16 | "bah", "baz", "fuz" 17 | ), 18 | ), 19 | array( 20 | array( 21 | "file" => __FILE__, 22 | "name" => "upload", 23 | "type" => "text/plain", 24 | ) 25 | ) 26 | ); 27 | 28 | echo $temp; 29 | 30 | ?> 31 | DONE 32 | --EXPECTF-- 33 | Test 34 | --%x.%x 35 | Content-Disposition: form-data; name="foo" 36 | 37 | bar 38 | --%x.%x 39 | Content-Disposition: form-data; name="more[0]" 40 | 41 | bah 42 | --%x.%x 43 | Content-Disposition: form-data; name="more[1]" 44 | 45 | baz 46 | --%x.%x 47 | Content-Disposition: form-data; name="more[2]" 48 | 49 | fuz 50 | --%x.%x 51 | Content-Disposition: form-data; name="upload"; filename="%s" 52 | Content-Transfer-Encoding: binary 53 | Content-Type: text/plain 54 | 55 | addForm( 60 | array( 61 | "foo" => "bar", 62 | "more" => array( 63 | "bah", "baz", "fuz" 64 | ), 65 | ), 66 | array( 67 | array( 68 | "file" => __FILE__, 69 | "name" => "upload", 70 | "type" => "text/plain", 71 | ) 72 | ) 73 | ); 74 | 75 | echo $temp; 76 | 77 | ?> 78 | DONE 79 | 80 | --%x.%x-- 81 | DONE 82 | -------------------------------------------------------------------------------- /tests/messagebody005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body add part 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getBoundary()); 13 | $temp->addPart(new http\Message("This: is a header\n\nand this is the data\n")); 14 | var_dump($temp->getBoundary()); 15 | echo $temp; 16 | 17 | ?> 18 | DONE 19 | --EXPECTF-- 20 | Test 21 | NULL 22 | string(%d) "%x.%x" 23 | --%x.%x 24 | This: is a header 25 | Content-Length: 21 26 | 27 | and this is the data 28 | 29 | --%x.%x-- 30 | DONE 31 | -------------------------------------------------------------------------------- /tests/messagebody006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body etag 3 | --SKIPIF-- 4 | 7 | --INI-- 8 | http.etag.mode = crc32b 9 | --FILE-- 10 | etag() 21 | ); 22 | var_dump($temp->etag()); 23 | 24 | ?> 25 | DONE 26 | --EXPECT-- 27 | Test 28 | bool(true) 29 | string(8) "00000000" 30 | DONE 31 | -------------------------------------------------------------------------------- /tests/messagebody007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body to stream 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toStream($f = fopen("php://temp", "w")); 13 | fseek($f, 0, SEEK_SET); 14 | var_dump(file_get_contents(__FILE__) === stream_get_contents($f)); 15 | 16 | ?> 17 | DONE 18 | --EXPECT-- 19 | Test 20 | bool(true) 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/messagebody008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body to callback 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toCallback( 14 | function($body, $string) use (&$s) { $s.=$string; } 15 | ); 16 | var_dump($s === (string) $file); 17 | 18 | ?> 19 | DONE 20 | --EXPECT-- 21 | Test 22 | bool(true) 23 | DONE 24 | -------------------------------------------------------------------------------- /tests/messagebody009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body clone 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | DONE 16 | --EXPECT-- 17 | Test 18 | bool(true) 19 | DONE 20 | -------------------------------------------------------------------------------- /tests/messagebody010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message body resource 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getResource(); 13 | var_dump(is_resource($stream)); 14 | $stat = fstat($stream); 15 | var_dump(filesize(__FILE__) === $stat["size"]); 16 | 17 | ?> 18 | DONE 19 | --EXPECT-- 20 | Test 21 | bool(true) 22 | bool(true) 23 | DONE 24 | -------------------------------------------------------------------------------- /tests/messageparser001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message parser 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | parse(fgets($fd), 0, $message)) { 20 | case Parser::STATE_DONE: 21 | $string = (string) $message; 22 | break 2; 23 | case Parser::STATE_FAILURE: 24 | throw new Exception(($e = error_get_last()) ? $e["message"] : "Could not parse $file"); 25 | } 26 | } 27 | 28 | if (!$string) { 29 | $s = array("START", "HEADER", "HEADER_DONE", "BODY", "BODY_DUMB", "BODY_LENGTH", "BODY_CHUNK", "BODY_DONE", "UPDATE_CL", "DONE"); 30 | printf("Unexpected state: %s (%s)\n", $s[$parser->getState()], $file); 31 | } 32 | 33 | $parser = new Parser; 34 | rewind($fd); 35 | unset($message); 36 | 37 | switch ($parser->stream($fd, 0, $message)) { 38 | case Parser::STATE_DONE: 39 | case Parser::STATE_START: 40 | break; 41 | default: 42 | printf("Expected parser state 0 or 8, got %d", $parser->getState()); 43 | } 44 | if ($string !== (string) $message) { 45 | $a = explode("\n", $string); 46 | $b = explode("\n", (string) $message); 47 | do { 48 | $aa = array_shift($a); 49 | $bb = array_shift($b); 50 | if ($aa !== $bb) { 51 | isset($aa) and printf("-- %s\n", $aa); 52 | isset($bb) and printf("++ %s\n", $bb); 53 | } 54 | } while ($a || $b); 55 | } 56 | } 57 | ?> 58 | DONE 59 | --EXPECT-- 60 | Test 61 | DONE 62 | -------------------------------------------------------------------------------- /tests/messageparser002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | message parser with nonblocking stream 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | stream($socket[0], 0, $msg); 26 | fwrite($socket[1], $line); 27 | $parser->stream($socket[0], 0, $msg); 28 | } 29 | 30 | var_dump($msg, (string) $msg->getBody()); 31 | 32 | ?> 33 | DONE 34 | --EXPECTF-- 35 | Test 36 | object(http\Message)#%d (9) { 37 | ["type":protected]=> 38 | int(1) 39 | ["body":protected]=> 40 | object(http\Message\Body)#%d (0) { 41 | } 42 | ["requestMethod":protected]=> 43 | string(3) "GET" 44 | ["requestUrl":protected]=> 45 | string(1) "/" 46 | ["responseStatus":protected]=> 47 | string(0) "" 48 | ["responseCode":protected]=> 49 | int(0) 50 | ["httpVersion":protected]=> 51 | string(3) "1.1" 52 | ["headers":protected]=> 53 | array(3) { 54 | ["Host"]=> 55 | string(9) "localhost" 56 | ["Content-Length"]=> 57 | string(1) "3" 58 | ["X-Original-Content-Length"]=> 59 | string(1) "3" 60 | } 61 | ["parentMessage":protected]=> 62 | NULL 63 | } 64 | string(3) "OK 65 | " 66 | DONE 67 | -------------------------------------------------------------------------------- /tests/params001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array("charset" => "iso-8859-1")); 22 | 23 | var_dump( 24 | isset($ct["text/html"]), 25 | isset($ct["text/json"]), 26 | $ct["text/json"]["arguments"]["charset"] 27 | ); 28 | 29 | var_dump((string) $ct,$ct); 30 | 31 | ?> 32 | DONE 33 | --EXPECTF-- 34 | Test 35 | bool(true) 36 | bool(false) 37 | string(5) "utf-8" 38 | bool(false) 39 | bool(true) 40 | string(10) "iso-8859-1" 41 | string(%d) "text/json;charset=iso-8859-1" 42 | object(http\Params)#%d (5) { 43 | ["params"]=> 44 | array(1) { 45 | ["text/json"]=> 46 | array(2) { 47 | ["value"]=> 48 | bool(true) 49 | ["arguments"]=> 50 | array(1) { 51 | ["charset"]=> 52 | string(10) "iso-8859-1" 53 | } 54 | } 55 | } 56 | ["param_sep"]=> 57 | string(1) "," 58 | ["arg_sep"]=> 59 | string(1) ";" 60 | ["val_sep"]=> 61 | string(1) "=" 62 | ["flags"]=> 63 | int(0) 64 | } 65 | DONE 66 | -------------------------------------------------------------------------------- /tests/params002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | query parser 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | DONE 16 | --EXPECTF-- 17 | object(http\Params)#%d (5) { 18 | ["params"]=> 19 | array(2) { 20 | ["foo"]=> 21 | array(2) { 22 | ["value"]=> 23 | string(3) "bar" 24 | ["arguments"]=> 25 | array(0) { 26 | } 27 | } 28 | ["arr"]=> 29 | array(2) { 30 | ["value"]=> 31 | array(2) { 32 | [0]=> 33 | string(1) "1" 34 | [1]=> 35 | string(1) "2" 36 | } 37 | ["arguments"]=> 38 | array(0) { 39 | } 40 | } 41 | } 42 | ["param_sep"]=> 43 | array(2) { 44 | [0]=> 45 | string(1) "&" 46 | [1]=> 47 | string(1) ";" 48 | } 49 | ["arg_sep"]=> 50 | string(0) "" 51 | ["val_sep"]=> 52 | string(1) "=" 53 | ["flags"]=> 54 | int(12) 55 | } 56 | foo=bar&arr%5B0%5D=1&arr%5B1%5D=2 57 | DONE 58 | 59 | -------------------------------------------------------------------------------- /tests/params003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | default params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "arg", "bar"=>"bla", "gotit"=>"now"); 16 | $r = array ( 17 | 'foo' => 18 | array ( 19 | 'value' => true, 20 | 'arguments' => 21 | array ( 22 | ), 23 | ), 24 | 'bar' => 25 | array ( 26 | 'value' => true, 27 | 'arguments' => 28 | array ( 29 | 'arg' => '0', 30 | 'bla' => true, 31 | ), 32 | ), 33 | 'gotit' => 34 | array ( 35 | 'value' => '0', 36 | 'arguments' => 37 | array ( 38 | 'now' => true, 39 | ), 40 | ), 41 | ); 42 | 43 | # --- 44 | 45 | var_dump(count($p->params)); 46 | 47 | echo "key exists\n"; 48 | foreach ($k as $key) { 49 | var_dump(array_key_exists($key, $p->params)); 50 | } 51 | 52 | echo "values\n"; 53 | foreach ($k as $key) { 54 | var_dump($p[$key]["value"]); 55 | } 56 | 57 | echo "args\n"; 58 | foreach ($k as $key) { 59 | var_dump(count($p[$key]["arguments"])); 60 | } 61 | 62 | echo "arg values\n"; 63 | foreach ($k as $key) { 64 | var_dump(@$p[$key]["arguments"][$a[$key]]); 65 | } 66 | 67 | echo "equals\n"; 68 | var_dump($c === (string) $p); 69 | var_dump($r === $p->params); 70 | $x = new http\Params($p->params); 71 | var_dump($r === $x->toArray()); 72 | ?> 73 | DONE 74 | --EXPECT-- 75 | Test 76 | int(3) 77 | key exists 78 | bool(true) 79 | bool(true) 80 | bool(true) 81 | values 82 | bool(true) 83 | bool(true) 84 | string(1) "0" 85 | args 86 | int(0) 87 | int(2) 88 | int(1) 89 | arg values 90 | NULL 91 | bool(true) 92 | bool(true) 93 | equals 94 | bool(true) 95 | bool(true) 96 | bool(true) 97 | DONE 98 | -------------------------------------------------------------------------------- /tests/params004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | custom params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "arg", "bar"=>"bla", "gotit"=>"now"); 16 | $r = array ( 17 | 'foo' => 18 | array ( 19 | 'value' => true, 20 | 'arguments' => 21 | array ( 22 | ), 23 | ), 24 | 'bar' => 25 | array ( 26 | 'value' => true, 27 | 'arguments' => 28 | array ( 29 | 'arg' => '0', 30 | 'bla' => true, 31 | ), 32 | ), 33 | 'gotit' => 34 | array ( 35 | 'value' => '0', 36 | 'arguments' => 37 | array ( 38 | 'now' => true, 39 | ), 40 | ), 41 | ); 42 | 43 | # --- 44 | 45 | var_dump(count($p->params)); 46 | 47 | echo "key exists\n"; 48 | foreach ($k as $key) { 49 | var_dump(array_key_exists($key, $p->params)); 50 | } 51 | 52 | echo "values\n"; 53 | foreach ($k as $key) { 54 | var_dump($p[$key]["value"]); 55 | } 56 | 57 | echo "args\n"; 58 | foreach ($k as $key) { 59 | var_dump(count($p[$key]["arguments"])); 60 | } 61 | 62 | echo "arg values\n"; 63 | foreach ($k as $key) { 64 | var_dump(@$p[$key]["arguments"][$a[$key]]); 65 | } 66 | 67 | echo "equals\n"; 68 | var_dump($c === (string) $p); 69 | var_dump($r === $p->params); 70 | $x = new http\Params($p->params); 71 | var_dump($r === $x->toArray()); 72 | ?> 73 | DONE 74 | --EXPECT-- 75 | Test 76 | int(3) 77 | key exists 78 | bool(true) 79 | bool(true) 80 | bool(true) 81 | values 82 | bool(true) 83 | bool(true) 84 | string(1) "0" 85 | args 86 | int(0) 87 | int(2) 88 | int(1) 89 | arg values 90 | NULL 91 | bool(true) 92 | bool(true) 93 | equals 94 | bool(true) 95 | bool(true) 96 | bool(true) 97 | DONE 98 | -------------------------------------------------------------------------------- /tests/params005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | quoted params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array( 14 | "value" => true, 15 | "arguments" => array( 16 | "boundary" => "--123" 17 | ) 18 | ) 19 | ); 20 | var_dump($c === $p->params); 21 | var_dump("multipart/form-data;boundary=--123" === (string) $p); 22 | ?> 23 | DONE 24 | --EXPECT-- 25 | Test 26 | bool(true) 27 | bool(true) 28 | DONE 29 | -------------------------------------------------------------------------------- /tests/params006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | escaped params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array( 14 | "value" => true, 15 | "arguments" => array( 16 | "name" => "upload", 17 | "filename" => "trick\"\0\"ed" 18 | ) 19 | ) 20 | ); 21 | var_dump($c === $p->params); 22 | var_dump("form-data;name=upload;filename=\"trick\\\"\\000\\\"ed\"" === (string) $p); 23 | ?> 24 | DONE 25 | --EXPECT-- 26 | Test 27 | bool(true) 28 | bool(true) 29 | DONE 30 | -------------------------------------------------------------------------------- /tests/params007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | urlencoded params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array( 15 | "value" => "b\"r", 16 | "arguments" => array(), 17 | ), 18 | "bar" => array( 19 | "value" => "b\"z", 20 | "arguments" => array(), 21 | ), 22 | "a[][]" => array( 23 | "value" => "1", 24 | "arguments" => array(), 25 | ), 26 | ); 27 | var_dump($c === $p->params); 28 | var_dump("foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1" === (string) $p); 29 | ?> 30 | DONE 31 | --EXPECT-- 32 | Test 33 | bool(true) 34 | bool(true) 35 | DONE 36 | -------------------------------------------------------------------------------- /tests/params008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | querystring params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array( 15 | "value" => "b\"r", 16 | "arguments" => array(), 17 | ), 18 | "bar" => array( 19 | "value" => "b\"z", 20 | "arguments" => array(), 21 | ), 22 | "a" => array( 23 | "value" => array( 24 | array("1") 25 | ), 26 | "arguments" => array(), 27 | ), 28 | ); 29 | var_dump($c === $p->params); 30 | var_dump("foo=b%22r&bar=b%22z&a%5B0%5D%5B0%5D=1" === (string) $p); 31 | ?> 32 | DONE 33 | --EXPECT-- 34 | Test 35 | bool(true) 36 | bool(true) 37 | DONE 38 | -------------------------------------------------------------------------------- /tests/params009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | empty params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | params); 12 | ?> 13 | DONE 14 | --EXPECT-- 15 | Test 16 | bool(true) 17 | DONE 18 | -------------------------------------------------------------------------------- /tests/params010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | int key params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array("value" => "nothing", "arguments" => array(1=>"yes"))) === $p->params); 13 | var_dump("0=nothing;1=yes" === $p->toString()); 14 | 15 | ?> 16 | DONE 17 | --EXPECT-- 18 | Test 19 | bool(true) 20 | bool(true) 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/params011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | bool args params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | false, "arguments" => array("wrong" => false, "correct" => true)); 13 | $p["container"] = $container; 14 | var_dump("container=0;wrong=0;correct" === $p->toString()); 15 | var_dump(array("container" => $container) === $p->toArray()); 16 | 17 | ?> 18 | DONE 19 | --EXPECT-- 20 | Test 21 | bool(true) 22 | bool(true) 23 | DONE 24 | -------------------------------------------------------------------------------- /tests/params012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | no args params 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toString()); 14 | $p["param"] = false; 15 | var_dump("param=0" === $p->toString()); 16 | ?> 17 | DONE 18 | --EXPECT-- 19 | Test 20 | bool(true) 21 | bool(true) 22 | DONE 23 | -------------------------------------------------------------------------------- /tests/params013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params rfc5987 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | params, (string) $p); 13 | $p = new http\Params("bar; title*=iso-8859-1'en'%A3%20rates"); 14 | var_dump($p->params, (string) $p); 15 | $p = new http\Params("bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates"); 16 | var_dump($p->params, (string) $p); 17 | 18 | ?> 19 | ===DONE=== 20 | --EXPECT-- 21 | Test 22 | array(1) { 23 | ["attachment"]=> 24 | array(2) { 25 | ["value"]=> 26 | bool(true) 27 | ["arguments"]=> 28 | array(1) { 29 | ["*rfc5987*"]=> 30 | array(1) { 31 | ["filename"]=> 32 | array(1) { 33 | [""]=> 34 | string(10) "döner.pdf" 35 | } 36 | } 37 | } 38 | } 39 | } 40 | string(42) "attachment;filename*=utf-8''d%C3%B6ner.pdf" 41 | array(1) { 42 | ["bar"]=> 43 | array(2) { 44 | ["value"]=> 45 | bool(true) 46 | ["arguments"]=> 47 | array(1) { 48 | ["*rfc5987*"]=> 49 | array(1) { 50 | ["title"]=> 51 | array(1) { 52 | ["en"]=> 53 | string(8) "£ rates" 54 | } 55 | } 56 | } 57 | } 58 | } 59 | string(34) "bar;title*=utf-8'en'%C2%A3%20rates" 60 | array(1) { 61 | ["bar"]=> 62 | array(2) { 63 | ["value"]=> 64 | bool(true) 65 | ["arguments"]=> 66 | array(1) { 67 | ["*rfc5987*"]=> 68 | array(1) { 69 | ["title"]=> 70 | array(1) { 71 | [""]=> 72 | string(16) "£ and € rates" 73 | } 74 | } 75 | } 76 | } 77 | } 78 | string(50) "bar;title*=utf-8''%C2%A3%20and%20%E2%82%AC%20rates" 79 | ===DONE=== 80 | -------------------------------------------------------------------------------- /tests/params014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params rfc5987 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | params); 15 | var_dump((string)$p === $t, (string)$p, $t); 16 | ?> 17 | ===DONE=== 18 | --EXPECT-- 19 | Test 20 | array(3) { 21 | ["p1"]=> 22 | array(2) { 23 | ["*rfc5987*"]=> 24 | array(1) { 25 | [""]=> 26 | string(5) "süß" 27 | } 28 | ["arguments"]=> 29 | array(0) { 30 | } 31 | } 32 | ["p2"]=> 33 | array(2) { 34 | ["*rfc5987*"]=> 35 | array(1) { 36 | [""]=> 37 | string(5) "heiß" 38 | } 39 | ["arguments"]=> 40 | array(2) { 41 | ["*rfc5987*"]=> 42 | array(2) { 43 | ["a1"]=> 44 | array(1) { 45 | [""]=> 46 | string(3) "aß" 47 | } 48 | ["a2"]=> 49 | array(1) { 50 | [""]=> 51 | string(3) "eß" 52 | } 53 | } 54 | ["a3"]=> 55 | string(2) "no" 56 | } 57 | } 58 | ["p3"]=> 59 | array(2) { 60 | ["value"]=> 61 | string(3) "not" 62 | ["arguments"]=> 63 | array(0) { 64 | } 65 | } 66 | } 67 | bool(true) 68 | string(96) "p1*=utf-8''s%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not" 69 | string(96) "p1*=utf-8''s%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not" 70 | ===DONE=== 71 | -------------------------------------------------------------------------------- /tests/params015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params rfc5987 regression 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | array("filename"=>"foo.bar"))); 11 | var_dump($p->params); 12 | var_dump((string)$p); 13 | ?> 14 | ===DONE=== 15 | --EXPECT-- 16 | Test 17 | array(1) { 18 | ["attachment"]=> 19 | array(1) { 20 | ["filename"]=> 21 | string(7) "foo.bar" 22 | } 23 | } 24 | string(27) "attachment;filename=foo.bar" 25 | ===DONE=== 26 | -------------------------------------------------------------------------------- /tests/params016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params rfc5988 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | ; rel="next", ; rel="last" 13 | EOF; 14 | 15 | $p = new http\Params($link, ",", ";", "=", 16 | http\Params::PARSE_RFC5988 | http\Params::PARSE_ESCAPED); 17 | var_dump($p->params); 18 | var_dump((string)$p); 19 | ?> 20 | ===DONE=== 21 | --EXPECT-- 22 | Test 23 | array(2) { 24 | ["https://api.github.com/search/code?q=addClass+user%3Amozilla&page=2"]=> 25 | array(2) { 26 | ["value"]=> 27 | bool(true) 28 | ["arguments"]=> 29 | array(1) { 30 | ["rel"]=> 31 | string(4) "next" 32 | } 33 | } 34 | ["https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34"]=> 35 | array(2) { 36 | ["value"]=> 37 | bool(true) 38 | ["arguments"]=> 39 | array(1) { 40 | ["rel"]=> 41 | string(4) "last" 42 | } 43 | } 44 | } 45 | string(162) ";rel="next",;rel="last"" 46 | ===DONE=== 47 | -------------------------------------------------------------------------------- /tests/params017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | header params rfc5988 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | ; 13 | rel="previous"; title*=UTF-8'de'letztes%20Kapitel, 14 | ; 15 | rel="next"; title*=UTF-8'de'n%c3%a4chstes%20Kapitel 16 | EOF; 17 | 18 | $p = current(http\Header::parse($link, "http\\Header"))->getParams( 19 | http\Params::DEF_PARAM_SEP, 20 | http\Params::DEF_ARG_SEP, 21 | http\Params::DEF_VAL_SEP, 22 | http\Params::PARSE_RFC5987 | http\Params::PARSE_RFC5988 | http\Params::PARSE_ESCAPED 23 | ); 24 | var_dump($p->params); 25 | var_dump((string)$p); 26 | ?> 27 | ===DONE=== 28 | --EXPECTF-- 29 | Test 30 | array(2) { 31 | ["/TheBook/chapter2"]=> 32 | array(2) { 33 | ["value"]=> 34 | bool(true) 35 | ["arguments"]=> 36 | array(2) { 37 | ["rel"]=> 38 | string(8) "previous" 39 | ["*rfc5987*"]=> 40 | array(1) { 41 | ["title"]=> 42 | array(1) { 43 | ["de"]=> 44 | string(15) "letztes Kapitel" 45 | } 46 | } 47 | } 48 | } 49 | ["/TheBook/chapter4"]=> 50 | array(2) { 51 | ["value"]=> 52 | bool(true) 53 | ["arguments"]=> 54 | array(2) { 55 | ["rel"]=> 56 | string(4) "next" 57 | ["*rfc5987*"]=> 58 | array(1) { 59 | ["title"]=> 60 | array(1) { 61 | ["de"]=> 62 | string(17) "nächstes Kapitel" 63 | } 64 | } 65 | } 66 | } 67 | } 68 | string(139) ";rel="previous";title*=utf-8'de'letztes%20Kapitel,;rel="next";title*=utf-8'de'n%C3%A4chstes%20Kapitel" 69 | ===DONE=== 70 | -------------------------------------------------------------------------------- /tests/phpinfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | phpinfo 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 12 | Done 13 | --EXPECTF-- 14 | Test 15 | %a 16 | HTTP Support => enabled 17 | Extension Version => 4.%s 18 | %a 19 | Done 20 | -------------------------------------------------------------------------------- /tests/querystring003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | querystring offset set 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 17 | ===DONE=== 18 | --EXPECT-- 19 | Test 20 | foo=bar&bar=baz 21 | bar=baz&foo=baz 22 | ===DONE=== 23 | -------------------------------------------------------------------------------- /tests/serialize001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | serialization 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | getClasses() as $class) { 13 | if ($class->isInstantiable()) { 14 | #printf("%s\n", $class->getName()); 15 | $instance = $class->newInstance(); 16 | $serialized = serialize($instance); 17 | $unserialized = unserialize($serialized); 18 | 19 | foreach (array("toString", "toArray") as $m) { 20 | if ($class->hasMethod($m)) { 21 | #printf("%s#%s\n", $class->getName(), $m); 22 | $unserialized->$m(); 23 | } 24 | } 25 | } 26 | } 27 | ?> 28 | DONE 29 | --EXPECTF-- 30 | DONE 31 | -------------------------------------------------------------------------------- /tests/skipif.inc: -------------------------------------------------------------------------------- 1 | =")) { 45 | die("skip need at least libcurl version $version\n"); 46 | } 47 | } 48 | 49 | function skip_http2_test($message = "skip need http2 support") { 50 | if (!defined("http\\Client\\Curl\\HTTP_VERSION_2_0")) { 51 | die("$message (HTTP_VERSION_2_0)\n"); 52 | } 53 | if (!(http\Client\Curl\FEATURES & http\Client\Curl\Features\HTTP2)) { 54 | die("$message (FEATURES & HTTP2)\n"); 55 | } 56 | foreach (explode(":", getenv("PATH")) as $path) { 57 | if (is_executable($path . "/nghttpd")) { 58 | return; 59 | } 60 | } 61 | die("$message (nghttpd in PATH)\n"); 62 | } 63 | -------------------------------------------------------------------------------- /tests/url001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url from env 3 | --SKIPIF-- 4 | 7 | --ENV-- 8 | SERVER_PORT=55555 9 | HTTP_HOST=example.com 10 | --GET-- 11 | s=b&i=0&e=&a[]=1&a[]=2 12 | --FILE-- 13 | "https", "port" => 443))); 17 | printf("%s\n", new http\Env\Url(array("path" => "/./up/../down/../././//index.php/.", "query" => null), null, http\Url::SANITIZE_PATH|http\Url::FROM_ENV)); 18 | printf("%s\n", new http\Env\Url(null, null, 0)); 19 | printf("%s\n", new http\Url(null, null, http\Url::FROM_ENV)); 20 | ?> 21 | DONE 22 | --EXPECTF-- 23 | http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2 24 | http://example.com:55555/index?s=b&i=0&e=&a[]=1&a[]=2 25 | https://example.com/?s=b&i=0&e=&a[]=1&a[]=2 26 | http://example.com:55555/index.php/ 27 | http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2 28 | http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2 29 | DONE 30 | -------------------------------------------------------------------------------- /tests/url002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url properties 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | "changed", "query" => "bar&foo=&added=this"), 17 | http\Url::JOIN_PATH | 18 | http\Url::JOIN_QUERY | 19 | http\Url::STRIP_AUTH | 20 | http\Url::STRIP_FRAGMENT 21 | ); 22 | 23 | var_dump($url->scheme); 24 | var_dump($url->user); 25 | var_dump($url->pass); 26 | var_dump($url->host); 27 | var_dump($url->port); 28 | var_dump($url->path); 29 | var_dump($url->query); 30 | var_dump($url->fragment); 31 | 32 | ?> 33 | DONE 34 | --EXPECT-- 35 | Test 36 | bool(true) 37 | string(4) "http" 38 | NULL 39 | NULL 40 | string(15) "www.example.com" 41 | int(8080) 42 | string(13) "/path/changed" 43 | string(47) "foo=&more%5B0%5D=1&more%5B1%5D=2&bar&added=this" 44 | NULL 45 | DONE 46 | -------------------------------------------------------------------------------- /tests/url003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url modification 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | mod(array("query" => "set=1"), http\Url::REPLACE); 16 | var_dump($tmp->toArray() != $mod->toArray()); 17 | var_dump("set=1" === $mod->query); 18 | var_dump("new_fragment" === $tmp->mod("#new_fragment")->fragment); 19 | 20 | ?> 21 | DONE 22 | --EXPECT-- 23 | Test 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | DONE 28 | -------------------------------------------------------------------------------- /tests/url004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url as string 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 18 | DONE 19 | --EXPECT-- 20 | Test 21 | bool(true) 22 | DONE 23 | -------------------------------------------------------------------------------- /tests/url005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url as array 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toArray()); 16 | var_dump($url->toArray() === $url2->toArray()); 17 | ?> 18 | DONE 19 | --EXPECT-- 20 | Test 21 | bool(true) 22 | DONE 23 | -------------------------------------------------------------------------------- /tests/urlparser004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/locale 3 | --SKIPIF-- 4 | 11 | --FILE-- 12 | 28 | DONE 29 | --EXPECTF-- 30 | Test 31 | 32 | sçheme: 33 | object(http\Url)#%d (8) { 34 | ["scheme"]=> 35 | string(7) "sçheme" 36 | ["user"]=> 37 | NULL 38 | ["pass"]=> 39 | NULL 40 | ["host"]=> 41 | NULL 42 | ["port"]=> 43 | NULL 44 | ["path"]=> 45 | NULL 46 | ["query"]=> 47 | NULL 48 | ["fragment"]=> 49 | NULL 50 | } 51 | 52 | sçheme://hƟst 53 | object(http\Url)#%d (8) { 54 | ["scheme"]=> 55 | string(7) "sçheme" 56 | ["user"]=> 57 | NULL 58 | ["pass"]=> 59 | NULL 60 | ["host"]=> 61 | string(5) "hƟst" 62 | ["port"]=> 63 | NULL 64 | ["path"]=> 65 | NULL 66 | ["query"]=> 67 | NULL 68 | ["fragment"]=> 69 | NULL 70 | } 71 | 72 | sçheme://hƟst:23/päth/öf/fıle 73 | object(http\Url)#%d (8) { 74 | ["scheme"]=> 75 | string(7) "sçheme" 76 | ["user"]=> 77 | NULL 78 | ["pass"]=> 79 | NULL 80 | ["host"]=> 81 | string(5) "hƟst" 82 | ["port"]=> 83 | int(23) 84 | ["path"]=> 85 | string(16) "/päth/öf/fıle" 86 | ["query"]=> 87 | NULL 88 | ["fragment"]=> 89 | NULL 90 | } 91 | DONE 92 | -------------------------------------------------------------------------------- /tests/urlparser005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/utf-8 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 22 | DONE 23 | --EXPECTF-- 24 | Test 25 | 26 | sçheme: 27 | object(http\Url)#%d (8) { 28 | ["scheme"]=> 29 | string(7) "sçheme" 30 | ["user"]=> 31 | NULL 32 | ["pass"]=> 33 | NULL 34 | ["host"]=> 35 | NULL 36 | ["port"]=> 37 | NULL 38 | ["path"]=> 39 | NULL 40 | ["query"]=> 41 | NULL 42 | ["fragment"]=> 43 | NULL 44 | } 45 | 46 | sçheme://hƟst 47 | object(http\Url)#%d (8) { 48 | ["scheme"]=> 49 | string(7) "sçheme" 50 | ["user"]=> 51 | NULL 52 | ["pass"]=> 53 | NULL 54 | ["host"]=> 55 | string(5) "hƟst" 56 | ["port"]=> 57 | NULL 58 | ["path"]=> 59 | NULL 60 | ["query"]=> 61 | NULL 62 | ["fragment"]=> 63 | NULL 64 | } 65 | 66 | sçheme://hƟst:23/päth/öf/fıle 67 | object(http\Url)#%d (8) { 68 | ["scheme"]=> 69 | string(7) "sçheme" 70 | ["user"]=> 71 | NULL 72 | ["pass"]=> 73 | NULL 74 | ["host"]=> 75 | string(5) "hƟst" 76 | ["port"]=> 77 | int(23) 78 | ["path"]=> 79 | string(16) "/päth/öf/fıle" 80 | ["query"]=> 81 | NULL 82 | ["fragment"]=> 83 | NULL 84 | } 85 | DONE 86 | -------------------------------------------------------------------------------- /tests/urlparser006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/locale/idna 3 | --SKIPIF-- 4 | 12 | --FILE-- 13 | 29 | DONE 30 | --EXPECTF-- 31 | Test 32 | 33 | sçheme: 34 | object(http\Url)#%d (8) { 35 | ["scheme"]=> 36 | string(7) "sçheme" 37 | ["user"]=> 38 | NULL 39 | ["pass"]=> 40 | NULL 41 | ["host"]=> 42 | NULL 43 | ["port"]=> 44 | NULL 45 | ["path"]=> 46 | NULL 47 | ["query"]=> 48 | NULL 49 | ["fragment"]=> 50 | NULL 51 | } 52 | 53 | sçheme://hƟst 54 | object(http\Url)#%d (8) { 55 | ["scheme"]=> 56 | string(7) "sçheme" 57 | ["user"]=> 58 | NULL 59 | ["pass"]=> 60 | NULL 61 | ["host"]=> 62 | string(11) "xn--hst-kwb" 63 | ["port"]=> 64 | NULL 65 | ["path"]=> 66 | NULL 67 | ["query"]=> 68 | NULL 69 | ["fragment"]=> 70 | NULL 71 | } 72 | 73 | sçheme://hƟst:23/päth/öf/fıle 74 | object(http\Url)#%d (8) { 75 | ["scheme"]=> 76 | string(7) "sçheme" 77 | ["user"]=> 78 | NULL 79 | ["pass"]=> 80 | NULL 81 | ["host"]=> 82 | string(11) "xn--hst-kwb" 83 | ["port"]=> 84 | int(23) 85 | ["path"]=> 86 | string(16) "/päth/öf/fıle" 87 | ["query"]=> 88 | NULL 89 | ["fragment"]=> 90 | NULL 91 | } 92 | DONE 93 | -------------------------------------------------------------------------------- /tests/urlparser007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/utf-8/idna 3 | --SKIPIF-- 4 | 10 | --FILE-- 11 | 25 | DONE 26 | --EXPECTF-- 27 | Test 28 | 29 | sçheme: 30 | object(http\Url)#%d (8) { 31 | ["scheme"]=> 32 | string(7) "sçheme" 33 | ["user"]=> 34 | NULL 35 | ["pass"]=> 36 | NULL 37 | ["host"]=> 38 | NULL 39 | ["port"]=> 40 | NULL 41 | ["path"]=> 42 | NULL 43 | ["query"]=> 44 | NULL 45 | ["fragment"]=> 46 | NULL 47 | } 48 | 49 | sçheme://hƟst 50 | object(http\Url)#%d (8) { 51 | ["scheme"]=> 52 | string(7) "sçheme" 53 | ["user"]=> 54 | NULL 55 | ["pass"]=> 56 | NULL 57 | ["host"]=> 58 | string(11) "xn--hst-kwb" 59 | ["port"]=> 60 | NULL 61 | ["path"]=> 62 | NULL 63 | ["query"]=> 64 | NULL 65 | ["fragment"]=> 66 | NULL 67 | } 68 | 69 | sçheme://hƟst:23/päth/öf/fıle 70 | object(http\Url)#%d (8) { 71 | ["scheme"]=> 72 | string(7) "sçheme" 73 | ["user"]=> 74 | NULL 75 | ["pass"]=> 76 | NULL 77 | ["host"]=> 78 | string(11) "xn--hst-kwb" 79 | ["port"]=> 80 | int(23) 81 | ["path"]=> 82 | string(16) "/päth/öf/fıle" 83 | ["query"]=> 84 | NULL 85 | ["fragment"]=> 86 | NULL 87 | } 88 | DONE 89 | -------------------------------------------------------------------------------- /tests/urlparser008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser ipv6 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getMessage(),"\n"; 24 | } 25 | } 26 | ?> 27 | DONE 28 | --EXPECTF-- 29 | Test 30 | 31 | s://[a:80 32 | http\Url::__construct(): Failed to parse hostinfo; expected ']' at pos 5 in '[a:80' 33 | 34 | s://[0] 35 | http\Url::__construct(): Failed to parse hostinfo; unexpected '[' at pos 0 in '[0]' 36 | 37 | s://[::1]:80 38 | object(http\Url)#%d (8) { 39 | ["scheme"]=> 40 | string(1) "s" 41 | ["user"]=> 42 | NULL 43 | ["pass"]=> 44 | NULL 45 | ["host"]=> 46 | string(5) "[::1]" 47 | ["port"]=> 48 | int(80) 49 | ["path"]=> 50 | NULL 51 | ["query"]=> 52 | NULL 53 | ["fragment"]=> 54 | NULL 55 | } 56 | 57 | s://mike@[0:0:0:0:0:FFFF:204.152.189.116]/foo 58 | object(http\Url)#%d (8) { 59 | ["scheme"]=> 60 | string(1) "s" 61 | ["user"]=> 62 | string(4) "mike" 63 | ["pass"]=> 64 | NULL 65 | ["host"]=> 66 | string(24) "[::ffff:204.152.189.116]" 67 | ["port"]=> 68 | NULL 69 | ["path"]=> 70 | string(4) "/foo" 71 | ["query"]=> 72 | NULL 73 | ["fragment"]=> 74 | NULL 75 | } 76 | DONE 77 | -------------------------------------------------------------------------------- /tests/urlparser010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/locale/topct 3 | --SKIPIF-- 4 | 14 | --FILE-- 15 | 28 | DONE 29 | --EXPECTF-- 30 | Test 31 | object(http\Url)#%d (8) { 32 | ["scheme"]=> 33 | string(4) "http" 34 | ["user"]=> 35 | string(4) "mike" 36 | ["pass"]=> 37 | string(12) "pa%C3%9Fwort" 38 | ["host"]=> 39 | string(15) "𐌀𐌁𐌂.it" 40 | ["port"]=> 41 | NULL 42 | ["path"]=> 43 | string(15) "/for/%E2%82%AC/" 44 | ["query"]=> 45 | string(9) "by=%C2%A2" 46 | ["fragment"]=> 47 | string(6) "%C3%B8" 48 | } 49 | DONE 50 | -------------------------------------------------------------------------------- /tests/urlparser011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/utf-8/topct 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 19 | DONE 20 | --EXPECTF-- 21 | Test 22 | object(http\Url)#%d (8) { 23 | ["scheme"]=> 24 | string(4) "http" 25 | ["user"]=> 26 | string(4) "mike" 27 | ["pass"]=> 28 | string(12) "pa%C3%9Fwort" 29 | ["host"]=> 30 | string(15) "𐌀𐌁𐌂.it" 31 | ["port"]=> 32 | NULL 33 | ["path"]=> 34 | string(15) "/for/%E2%82%AC/" 35 | ["query"]=> 36 | string(9) "by=%C2%A2" 37 | ["fragment"]=> 38 | string(6) "%C3%B8" 39 | } 40 | DONE 41 | -------------------------------------------------------------------------------- /tests/urlparser012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/locale/topct 3 | --SKIPIF-- 4 | 13 | --FILE-- 14 | 27 | DONE 28 | --EXPECTF-- 29 | Test 30 | object(http\Url)#%d (8) { 31 | ["scheme"]=> 32 | string(4) "http" 33 | ["user"]=> 34 | string(4) "mike" 35 | ["pass"]=> 36 | string(12) "pa%C3%9Fwort" 37 | ["host"]=> 38 | string(13) "xn--097ccd.it" 39 | ["port"]=> 40 | NULL 41 | ["path"]=> 42 | string(15) "/for/%E2%82%AC/" 43 | ["query"]=> 44 | string(9) "by=%C2%A2" 45 | ["fragment"]=> 46 | string(6) "%C3%B8" 47 | } 48 | DONE 49 | -------------------------------------------------------------------------------- /tests/urlparser013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | url parser multibyte/utf-8/topct 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 21 | DONE 22 | --EXPECTF-- 23 | Test 24 | object(http\Url)#%d (8) { 25 | ["scheme"]=> 26 | string(4) "http" 27 | ["user"]=> 28 | string(4) "mike" 29 | ["pass"]=> 30 | string(12) "pa%C3%9Fwort" 31 | ["host"]=> 32 | string(13) "xn--097ccd.it" 33 | ["port"]=> 34 | NULL 35 | ["path"]=> 36 | string(15) "/for/%E2%82%AC/" 37 | ["query"]=> 38 | string(9) "by=%C2%A2" 39 | ["fragment"]=> 40 | string(6) "%C3%B8" 41 | } 42 | DONE 43 | -------------------------------------------------------------------------------- /tests/version001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | version parse error 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setHttpVersion("1-1"); 13 | $m->setHttpVersion("one.one"); 14 | } catch (http\Exception $e) { 15 | echo $e->getMessage(),"\n"; 16 | } 17 | ?> 18 | --EXPECTF-- 19 | Notice: http\Message::setHttpVersion(): Non-standard version separator '-' in HTTP protocol version '1-1' in %s 20 | http\Message::setHttpVersion(): Could not parse HTTP protocol version 'one.one' 21 | 22 | --------------------------------------------------------------------------------