PHP_ARG_WITH([http-libevent-dir], [],
[ --with-http-libevent-dir[=DIR] HTTP: where to find libevent], $PHP_HTTP_LIBCURL_DIR, "")
PHP_ARG_WITH([http-libidn-dir], [],
-[ --with-http-libidn-dir=[=DIR] HTTP: where to find libidn], $PHP_HTTP_LIBCURL_DIR, "")
+[ --with-http-libidn-dir[=DIR] HTTP: where to find libidn], $PHP_HTTP_LIBCURL_DIR, "")
if test "$PHP_HTTP" != "no"; then
break;
fi
done
- if test "x$IDNA_DIR" = "x"; then
- AC_MSG_RESULT([not found])
- case $host_os in
- darwin*)
- AC_CHECK_HEADERS(unicode/uidna.h)
- PHP_CHECK_FUNC(uidna_IDNToASCII, icucore);;
- esac
- else
+ if test "x$IDNA_DIR" != "x"; then
AC_MSG_RESULT([found in $IDNA_DIR])
AC_DEFINE([PHP_HTTP_HAVE_IDN], [1], [Have libidn support])
PHP_ADD_INCLUDE($IDNA_DIR/include)
PHP_ADD_LIBRARY_WITH_PATH(idn, $IDNA_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
+ AC_MSG_CHECKING([for libidn version])
+ IDNA_VER=$(pkg-config --version libidn 2>/dev/null || echo unknown)
+ AC_MSG_RESULT([$IDNA_VER])
+ AC_DEFINE_UNQUOTED([PHP_HTTP_LIBIDN_VERSION], "$IDNA_VER", [ ])
+ else
+ AC_MSG_RESULT([not found])
+ AC_MSG_CHECKING([for idn2.h])
+ IDNA_DIR=
+ for i in "$PHP_HTTP_LIBIDN_DIR" "$IDN_DIR" /usr/local /usr /opt; do
+ if test -f "$i/include/idn2.h"; then
+ IDNA_DIR=$i
+ break;
+ fi
+ done
+ if test "x$IDNA_DIR" != "x"; then
+ AC_MSG_RESULT([found in $IDNA_DIR])
+ AC_DEFINE([PHP_HTTP_HAVE_IDN2], [1], [Have libidn2 support])
+ PHP_ADD_INCLUDE($IDNA_DIR/include)
+ PHP_ADD_LIBRARY_WITH_PATH(idn2, $IDNA_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
+ AC_MSG_CHECKING([for libidn2 version])
+ IDNA_VER=`$EGREP "define IDN2_VERSION " $IDNA_DIR/include/idn2.h | $SED -e's/^.*VERSION //g' -e 's/[[^0-9\.]]//g'`
+ AC_MSG_RESULT([$IDNA_VER])
+ AC_DEFINE_UNQUOTED([PHP_HTTP_LIBIDN2_VERSION], "$IDNA_VER", [ ])
+ else
+ AC_MSG_RESULT([not found])
+ AC_CHECK_HEADERS([unicode/uidna.h])
+ case $host_os in
+ darwin*)
+ PHP_CHECK_FUNC(uidna_IDNToASCII, icucore);;
+ *)
+ AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
+ if test ! -x "$ICU_CONFIG"; then
+ ICU_CONFIG="icu-config"
+ fi
+ AC_MSG_CHECKING([for uidna_IDNToASCII])
+ if ! test -x "$ICU_CONFIG"; then
+ ICU_CONFIG=icu-config
+ fi
+ if $ICU_CONFIG --exists 2>/dev/null >&2; then
+ save_LIBS=$LIBS
+ LIBS=$($ICU_CONFIG --ldflags)
+ AC_TRY_RUN([
+ #include <unicode/uidna.h>
+ int main(int argc, char *argv[]) {
+ return uidna_IDNToASCII(0, 0, 0, 0, 0, 0, 0);
+ }
+ ], [
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_UIDNA_IDNTOASCII], [1], [ ])
+ LIBS=$save_LIBS
+ PHP_EVAL_LIBLINE(`$ICU_CONFIG --ldflags`, HTTP_SHARED_LIBADD)
+ ], [
+ LIBS=$save_LIBS
+ AC_MSG_RESULT([no])
+ ])
+ fi
+ ;;
+ esac
+ fi
fi
dnl ----
<email>mike@php.net</email>
<active>yes</active>
</lead>
- <date>2015-03-18</date>
+ <date>2015-04-08</date>
<version>
- <release>2.4.0</release>
+ <release>2.4.4dev</release>
<api>2.4.0</api>
</version>
<stability>
</stability>
<license>BSD, revised</license>
<notes><![CDATA[
-* Split off pecl/apfd and pecl/json_post
+*
]]></notes>
<contents>
<dir name="/">
<file role="test" name="bug66891.phpt"/>
<file role="test" name="bug67932.phpt"/>
<file role="test" name="bug69000.phpt"/>
+ <file role="test" name="bug69076.phpt"/>
+ <file role="test" name="bug69357.phpt"/>
<file role="test" name="client001.phpt"/>
<file role="test" name="client002.phpt"/>
<file role="test" name="client003.phpt"/>
# endif
# endif
#endif
-#if PHP_HTTP_HAVE_SERF
-# include <serf.h>
+#if PHP_HTTP_HAVE_IDN2
+# include <idn2.h>
+#elif PHP_HTTP_HAVE_IDN
+# include <idna.h>
#endif
ZEND_DECLARE_MODULE_GLOBALS(php_http);
php_info_print_table_row(3, "libevent", "disabled", "disabled");
#endif
+#if PHP_HTTP_HAVE_IDN2
+ php_info_print_table_row(3, "libidn2 (IDNA2008)", IDN2_VERSION, idn2_check_version(NULL));
+#elif PHP_HTTP_HAVE_IDN
+ php_info_print_table_row(3, "libidn (IDNA2003)", PHP_HTTP_LIBIDN_VERSION, "unknown");
+#endif
+
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define PHP_PECL_HTTP_VERSION "2.4.0"
+#define PHP_PECL_HTTP_VERSION "2.4.4dev"
extern zend_module_entry http_module_entry;
#define phpext_http_ptr &http_module_entry
response = php_http_message_init(NULL, 0, h->response.body TSRMLS_CC);
php_http_header_parser_init(&parser TSRMLS_CC);
- php_http_header_parser_parse(&parser, &h->response.headers, PHP_HTTP_HEADER_PARSER_CLEANUP, &response->hdrs, (php_http_info_callback_t) php_http_message_info_callback, (void *) &response);
+ while (h->response.headers.used) {
+ php_http_header_parser_state_t st = php_http_header_parser_parse(&parser,
+ &h->response.headers, PHP_HTTP_HEADER_PARSER_CLEANUP, &response->hdrs,
+ (php_http_info_callback_t) php_http_message_info_callback, (void *) &response);
+ if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE == st) {
+ break;
+ }
+ }
php_http_header_parser_dtor(&parser);
/* move body to right message */
while (ptr->parent) {
ptr = ptr->parent;
}
+ php_http_message_body_free(&response->body);
response->body = ptr->body;
ptr->body = NULL;
}
static void php_http_curlm_responsehandler(php_http_client_t *context)
{
- int remaining = 0;
+ int err_count = 0, remaining = 0;
+ php_http_curle_storage_t *st, *err = NULL;
php_http_client_enqueue_t *enqueue;
php_http_client_curl_t *curl = context->ctx;
TSRMLS_FETCH_FROM_CTX(context->ts);
if (msg && CURLMSG_DONE == msg->msg) {
if (CURLE_OK != msg->data.result) {
- php_http_curle_storage_t *st = php_http_curle_get_storage(msg->easy_handle);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s; %s (%s)", curl_easy_strerror(st->errorcode = msg->data.result), STR_PTR(st->errorbuffer), STR_PTR(st->url));
+ st = php_http_curle_get_storage(msg->easy_handle);
+ st->errorcode = msg->data.result;
+
+ /* defer the warnings/exceptions, so the callback is still called for this request */
+ if (!err) {
+ err = ecalloc(remaining + 1, sizeof(*err));
+ }
+ memcpy(&err[err_count], st, sizeof(*st));
+ if (st->url) {
+ err[err_count].url = estrdup(st->url);
+ }
+ err_count++;
}
if ((enqueue = php_http_client_enqueued(context, msg->easy_handle, compare_queue))) {
}
}
} while (remaining);
+
+ if (err_count) {
+ int i = 0;
+
+ do {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s; %s (%s)", curl_easy_strerror(err[i].errorcode), err[i].errorbuffer, STR_PTR(err[i].url));
+ if (err[i].url) {
+ efree(err[i].url);
+ }
+ } while (++i < err_count);
+
+ efree(err);
+ }
}
#if PHP_HTTP_HAVE_EVENT
php_http_url_to_string(PHP_HTTP_INFO(msg).request.url, &storage->url, NULL, 1);
curl_easy_setopt(curl->handle, CURLOPT_URL, storage->url);
- /* request method */
- switch (php_http_select_str(PHP_HTTP_INFO(msg).request.method, 4, "GET", "HEAD", "POST", "PUT")) {
- case 0:
- curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L);
- break;
-
- case 1:
- curl_easy_setopt(curl->handle, CURLOPT_NOBODY, 1L);
- break;
-
- case 2:
- curl_easy_setopt(curl->handle, CURLOPT_POST, 1L);
- break;
-
- case 3:
- curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
- break;
-
- default: {
- if (PHP_HTTP_INFO(msg).request.method) {
- curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, PHP_HTTP_INFO(msg).request.method);
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot use empty request method");
- return FAILURE;
- }
- break;
- }
- }
-
/* apply options */
php_http_options_apply(&php_http_curle_options, enqueue->options, curl);
curl_easy_setopt(curl->handle, CURLOPT_READDATA, msg->body);
curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
+ curl_easy_setopt(curl->handle, CURLOPT_POST, 1L);
} else {
curl_easy_setopt(curl->handle, CURLOPT_SEEKDATA, NULL);
curl_easy_setopt(curl->handle, CURLOPT_READDATA, NULL);
curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, 0L);
}
+ /*
+ * Always use CUSTOMREQUEST, else curl won't send any request body for GET etc.
+ * See e.g. bug #69313.
+ *
+ * Here's what curl does:
+ * - CURLOPT_HTTPGET: ignore request body
+ * - CURLOPT_UPLOAD: set "Expect: 100-continue" header
+ * - CURLOPT_POST: set "Content-Type: application/x-www-form-urlencoded" header
+ * Now select the least bad.
+ *
+ * See also https://tools.ietf.org/html/rfc7231#section-5.1.1
+ */
+ if (PHP_HTTP_INFO(msg).request.method) {
+ if (!strcasecmp("PUT", PHP_HTTP_INFO(msg).request.method)) {
+ curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
+ } else {
+ curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, PHP_HTTP_INFO(msg).request.method);
+ }
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot use empty request method");
+ return FAILURE;
+ }
+
return SUCCESS;
}
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in event_base_dispatch()");
return FAILURE;
}
- } while (curl->unfinished);
+ } while (curl->unfinished && !EG(exception));
} else
#endif
{
- while (php_http_client_curl_once(h)) {
+ while (php_http_client_curl_once(h) && !EG(exception)) {
if (SUCCESS != php_http_client_curl_wait(h, NULL)) {
#ifdef PHP_WIN32
/* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
#include "php_http_api.h"
-#ifdef PHP_HTTP_HAVE_IDN
+#if PHP_HTTP_HAVE_IDN2
+# include <idn2.h>
+#elif PHP_HTTP_HAVE_IDN
# include <idna.h>
#endif
#if defined(PHP_WIN32) || defined(HAVE_UIDNA_IDNTOASCII)
typedef size_t (*parse_mb_func)(unsigned *wc, const char *ptr, const char *end);
-static ZEND_RESULT_CODE to_utf16(parse_mb_func fn, const char *u8, uint16_t **u16, size_t *len)
+static ZEND_RESULT_CODE to_utf16(parse_mb_func fn, const char *u8, uint16_t **u16, size_t *len TSRMLS_DC)
{
size_t offset = 0, u8_len = strlen(u8);
# define MAXHOSTNAMELEN 256
#endif
-#ifdef PHP_HTTP_HAVE_IDN
+#if PHP_HTTP_HAVE_IDN2
+static ZEND_RESULT_CODE parse_idn2(struct parse_state *state, size_t prev_len)
+{
+ char *idn = NULL;
+ int rv = -1;
+ TSRMLS_FETCH_FROM_CTX(state->ts);
+
+ if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
+ rv = idn2_lookup_u8((const unsigned char *) state->url.host, (unsigned char **) &idn, IDN2_NFC_INPUT);
+ }
+# ifdef PHP_HTTP_HAVE_WCHAR
+ else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
+ rv = idn2_lookup_ul(state->url.host, &idn, 0);
+ }
+# endif
+ if (rv != IDN2_OK) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
+ return FAILURE;
+ } else {
+ size_t idnlen = strlen(idn);
+ memcpy(state->url.host, idn, idnlen + 1);
+ free(idn);
+ state->offset += idnlen - prev_len;
+ return SUCCESS;
+ }
+}
+#elif PHP_HTTP_HAVE_IDN
static ZEND_RESULT_CODE parse_idn(struct parse_state *state, size_t prev_len)
{
char *idn = NULL;
TSRMLS_FETCH_FROM_CTX(state->ts);
if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
- if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len)) {
+ if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len TSRMLS_CC)) {
return FAILURE;
}
#ifdef PHP_HTTP_HAVE_WCHAR
} else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
- if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len)) {
+ if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len TSRMLS_CC)) {
return FAILURE;
}
#endif
}
if (state->flags & PHP_HTTP_URL_PARSE_TOIDN) {
-#ifdef PHP_HTTP_HAVE_IDN
+#if PHP_HTTP_HAVE_IDN2
+ return parse_idn2(state, len);
+#elif PHP_HTTP_HAVE_IDN
return parse_idn(state, len);
#endif
#ifdef HAVE_UIDNA_IDNTOASCII
tmp = ++state->ptr;
state->url.query = &state->buffer[state->offset];
- do {
+ while (state->ptr < state->end) {
switch (*state->ptr) {
case '#':
goto done;
}
state->ptr += mb - 1;
}
- } while (++state->ptr < state->end);
+
+ ++state->ptr;
+ }
done:
state->buffer[state->offset++] = 0;
zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
#endif
zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
-#if defined(PHP_HTTP_HAVE_IDN) || defined(HAVE_UIDNA_IDNTOASCII)
+#if defined(PHP_HTTP_HAVE_IDN2) || defined(PHP_HTTP_HAVE_IDN) || defined(HAVE_UIDNA_IDNTOASCII)
zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC);
#endif
zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC);
--- /dev/null
+--TEST--
+Bug #69076 (URL parsing throws exception on empty query string)
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+echo new http\Url("http://foo.bar/?");
+?>
+
+===DONE===
+--EXPECT--
+Test
+http://foo.bar/
+===DONE===
--- /dev/null
+--TEST--
+Bug #69313 (http\Client doesn't send GET body)
+--SKIPIF--
+<?php
+include "./skipif.inc";
+skip_client_test();
+?>
+--FILE--
+<?php
+
+
+include "helper/server.inc";
+
+echo "Test\n";
+
+server("proxy.inc", function($port, $stdin, $stdout, $stderr) {
+ $request = new http\Client\Request("GET", "http://localhost:$port/");
+ $request->setHeader("Content-Type", "text/plain");
+ $request->getBody()->append("foo");
+ $client = new http\Client();
+ $client->enqueue($request);
+ $client->send();
+ echo $client->getResponse();
+});
+
+?>
+
+Done
+--EXPECTF--
+Test
+HTTP/1.1 200 OK
+Accept-Ranges: bytes
+Etag: "%s"
+X-Original-Transfer-Encoding: chunked
+Content-Length: %d
+
+GET / HTTP/1.1
+User-Agent: %s
+Host: localhost:%d
+Accept: */*
+Content-Type: text/plain
+Content-Length: 3
+X-Original-Content-Length: 3
+
+foo
+Done
--- /dev/null
+--TEST--
+Bug #69357 (HTTP/1.1 100 Continue overriding subsequent 200 response code with PUT request)
+--SKIPIF--
+<?php
+include "skipif.inc";
+skip_client_test();
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "helper/server.inc";
+
+server("upload.inc", function($port) {
+ $r = new \http\Client\Request("PUT", "http://localhost:$port/", [],
+ (new \http\Message\Body)->append("foo")
+ );
+ $c = new \http\Client;
+ $c->setOptions(["expect_100_timeout" => 0]);
+ $c->enqueue($r)->send();
+
+ var_dump($c->getResponse($r)->getInfo());
+ var_dump($c->getResponse($r)->getHeaders());
+});
+
+?>
+===DONE===
+--EXPECTF--
+Test
+string(15) "HTTP/1.1 200 OK"
+array(4) {
+ ["Accept-Ranges"]=>
+ string(5) "bytes"
+ ["Etag"]=>
+ string(10) ""%x""
+ ["X-Original-Transfer-Encoding"]=>
+ string(7) "chunked"
+ ["Content-Length"]=>
+ int(%d)
+}
+===DONE===
--- /dev/null
+<?php
+
+include "server.inc";
+
+serve(function($client) {
+ $request = new http\Message($client, false);
+
+ if ($request->getHeader("Expect") === "100-continue") {
+ $response = new http\Env\Response;
+ $response->setEnvRequest($request);
+ $response->setResponseCode(100);
+ $response->send($client);
+ }
+
+ /* return the initial message as response body */
+ $response = new http\Env\Response;
+ /* avoid OOM with $response->getBody()->append($request); */
+ $request->toStream($response->getBody()->getResource());
+ $response->send($client);
+});