From 280b469e963c4e96a1cc8de6c500ed58aaf629b5 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sat, 2 Mar 2013 20:13:19 +0000 Subject: [PATCH] * Fixed Bug #64310 (weak etags W/"abc" are quoted as "W/"abc"") --- http_request_api.c | 23 ++++++++++++++++++++--- package.xml | 6 +++--- php_http.h | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/http_request_api.c b/http_request_api.c index 1b0c59e..b6e4034 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -872,12 +872,29 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* etag */ if ((zoption = http_request_option(request, options, "etag", IS_STRING)) && Z_STRLEN_P(zoption)) { - zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"')); + zend_bool is_quoted; phpstr header; - + phpstr_init(&header); - phpstr_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", range_req?"If-Match":"If-None-Match", Z_STRVAL_P(zoption)); + phpstr_appendf(&header, "%s: ", range_req?"If-Match":"If-None-Match"); + if ((Z_STRVAL_P(zoption)[0] == '"') && (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] == '"')) { + /* properly quoted etag */ + phpstr_append(&header, Z_STRVAL_P(zoption), Z_STRLEN_P(zoption)); + } else if ((Z_STRVAL_P(zoption)[0] == 'W') && (Z_STRVAL_P(zoption)[1] == '/')) { + /* weak etag */ + if ((Z_STRLEN_P(zoption) > 3) && (Z_STRVAL_P(zoption)[2] == '"') && (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] == '"')) { + /* quoted */ + phpstr_append(&header, Z_STRVAL_P(zoption), Z_STRLEN_P(zoption)); + } else { + /* unquoted */ + phpstr_appendf(&header, "W/\"%s\"", Z_STRVAL_P(zoption) + 2); + } + } else { + /* assume unquoted etag */ + phpstr_appendf(&header, "\"%s\"", Z_STRVAL_P(zoption)); + } phpstr_fix(&header); + request->_cache.headers = curl_slist_append(request->_cache.headers, PHPSTR_VAL(&header)); phpstr_dtor(&header); } diff --git a/package.xml b/package.xml index 1440438..4adfb6f 100644 --- a/package.xml +++ b/package.xml @@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater. mike@php.net yes - 2012-04-02 + 2013-03-02 - 1.7.4 + 1.7.5dev 1.7.0 @@ -39,7 +39,7 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised diff --git a/php_http.h b/php_http.h index 0762c07..023be4f 100644 --- a/php_http.h +++ b/php_http.h @@ -15,7 +15,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_HTTP_VERSION "1.7.4" +#define PHP_HTTP_VERSION "1.7.5dev" #ifdef HAVE_CONFIG_H # include "config.h" -- 2.30.2