php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC)
{
- const char *end, *http;
+ const char *end, *http, *off;
zend_bool free_info = !info;
/* sane parameter */
info = php_http_info_init(info TSRMLS_CC);
- /* and nothing than SPACE or NUL after HTTP/X.x */
- if (!php_http_version_parse(&info->http.version, http TSRMLS_CC)
- || (http[lenof("HTTP/X.x")] && (!PHP_HTTP_IS_CTYPE(space, http[lenof("HTTP/X.x")])))) {
+ if (!php_http_version_parse(&info->http.version, http TSRMLS_CC)) {
+ if (free_info) {
+ php_http_info_free(&info);
+ }
+ return NULL;
+ }
+
+ /* clumsy fix for changed libcurl behaviour in 7.49.1, see https://github.com/curl/curl/issues/888 */
+ off = &http[lenof("HTTP/X")];
+ if (info->http.version.major < 2) {
+ off += 2;
+ }
+
+ /* and nothing than SPACE or NUL after HTTP/X(.x) */
+ if (*off && (!PHP_HTTP_IS_CTYPE(space, *off))) {
if (free_info) {
php_http_info_free(&info);
}
/* is response */
if (pre_header == http) {
- const char *status = NULL, *code = http + sizeof("HTTP/X.x");
+ const char *status = NULL, *code = off;
info->type = PHP_HTTP_RESPONSE;
while (' ' == *code) ++code;
- if (code && end > code) {
+ if (end > code) {
/* rfc7230#3.1.2 The status-code element is a 3-digit integer code */
PHP_HTTP_INFO(info).response.code = 100*(*code++ - '0');
PHP_HTTP_INFO(info).response.code += 10*(*code++ - '0');
}
/* is request */
- else if (*(http - 1) == ' ' && (!http[lenof("HTTP/X.x")] || http[lenof("HTTP/X.x")] == '\r' || http[lenof("HTTP/X.x")] == '\n')) {
+ else if (*(http - 1) == ' ' && (!*off || *off == '\r' || *off == '\n')) {
const char *url = strchr(pre_header, ' ');
info->type = PHP_HTTP_REQUEST;
return info;
}
- /* some darn header containing HTTP/X.x */
+ /* some darn header containing HTTP/X(.x) */
else {
if (free_info) {
php_http_info_free(&info);
major = *ptr++ - '0';
if (major >= 0 && major <= 9) {
separator = *ptr++;
- if (separator) {
- if (separator != '.' && separator != ',') {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2);
- }
+ switch (separator) {
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2);
+ /* no break */
+ case '.':
+ case ',':
minor = *ptr - '0';
- if (minor >= 0 && minor <= 9) {
- return php_http_version_init(v, major, minor TSRMLS_CC);
+ break;
+
+ case ' ':
+ if (major > 1) {
+ minor = 0;
+ } else {
+ goto error;
}
}
+ if (minor >= 0 && minor <= 9) {
+ return php_http_version_init(v, major, minor TSRMLS_CC);
+ }
}
}
+ error:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP protocol version '%s'", str);
return NULL;
}
$client->setOptions([
"protocol" => http\Client\Curl\HTTP_VERSION_2_0,
"ssl" => [
- "cafile" => __DIR__."/helper/http2.crt",
+ "cainfo" => __DIR__."/helper/http2.crt",
]
]);
- $client->enqueue(new http\Client\Request("GET", "https://localhost:$port"));
+
+ $request = new http\Client\Request("GET", "https://localhost:$port");
+ $client->enqueue($request);
echo $client->send()->getResponse();
});