[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 13/411: etag: save and use the full received contents
From: |
gnunet |
Subject: |
[gnurl] 13/411: etag: save and use the full received contents |
Date: |
Wed, 13 Jan 2021 01:17:08 +0100 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 98c94596f5928840177b6bd3c7b0f0dd03a431af
Author: Daniel Stenberg <daniel@haxx.se>
AuthorDate: Thu Aug 20 00:34:44 2020 +0200
etag: save and use the full received contents
... which makes it support weak tags and non-standard etags too!
Added test case 347 to verify blank incoming ETag:
Fixes #5610
Closes #5833
---
src/tool_cb_hdr.c | 56 +++++++++++------------------------------
src/tool_operate.c | 2 +-
tests/data/Makefile.inc | 2 +-
tests/data/test1566 | 2 +-
tests/data/test339 | 4 +--
tests/data/test342 | 2 +-
tests/data/test343 | 4 +--
tests/data/test344 | 2 +-
tests/data/test345 | 4 +--
tests/data/{test339 => test347} | 11 ++++----
10 files changed, 31 insertions(+), 58 deletions(-)
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c
index 5741f0aba..ee3ef7390 100644
--- a/src/tool_cb_hdr.c
+++ b/src/tool_cb_hdr.c
@@ -98,53 +98,27 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb,
void *userdata)
/*
* Write etag to file when --etag-save option is given.
- * etag string that we want is enveloped in double quotes
*/
if(per->config->etag_save_file && etag_save->stream) {
/* match only header that start with etag (case insensitive) */
if(curl_strnequal(str, "etag:", 5)) {
- char *etag_h = NULL;
- char *first = NULL;
- char *last = NULL;
- size_t etag_length = 0;
-
- etag_h = ptr;
- /* point to first occurrence of double quote */
- first = memchr(etag_h, '\"', cb);
-
- /*
- * if server side messed with the etag header and doesn't include
- * double quotes around the etag, kindly exit with a warning
- */
-
- if(!first) {
- warnf(per->config->global,
- "Received header etag is missing double quote/s\n");
- return failure;
- }
- else {
- /* discard first double quote */
- first++;
- }
-
- /* point to last occurrence of double quote */
- last = memchr(first, '\"', cb);
-
- if(!last) {
- warnf(per->config->global,
- "Received header etag is missing double quote/s\n");
- return failure;
+ const char *etag_h = &str[5];
+ const char *eot = end - 1;
+ if(*eot == '\n') {
+ while(ISSPACE(*etag_h) && (etag_h < eot))
+ etag_h++;
+ while(ISSPACE(*eot))
+ eot--;
+
+ if(eot >= etag_h) {
+ size_t etag_length = eot - etag_h + 1;
+ fwrite(etag_h, size, etag_length, etag_save->stream);
+ /* terminate with newline */
+ fputc('\n', etag_save->stream);
+ (void)fflush(etag_save->stream);
+ }
}
-
- /* get length of desired etag */
- etag_length = (size_t)last - (size_t)first;
-
- fwrite(first, size, etag_length, etag_save->stream);
- /* terminate with new line */
- fputc('\n', etag_save->stream);
}
-
- (void)fflush(etag_save->stream);
}
/*
diff --git a/src/tool_operate.c b/src/tool_operate.c
index ad4e85dd8..3936315a9 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -922,7 +922,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if((PARAM_OK == file2string(&etag_from_file, file)) &&
etag_from_file) {
- header = aprintf("If-None-Match: \"%s\"", etag_from_file);
+ header = aprintf("If-None-Match: %s", etag_from_file);
Curl_safefree(etag_from_file);
}
else
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index 3752502ef..9261ee221 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -58,7 +58,7 @@ test307 test308 test309 test310 test311 test312 test313
test314 test315 \
test316 test317 test318 test319 test320 test321 test322 test323 test324 \
test325 test326 test327 test328 test329 test330 test331 test332 test333 \
test334 test335 test336 test337 test338 test339 test340 test341 test342 \
-test343 test344 test345 test346 \
+test343 test344 test345 test346 test347 \
test350 test351 test352 test353 test354 test355 test356 test357 test358 \
test359 \
test393 test394 test395 test396 test397 \
diff --git a/tests/data/test1566 b/tests/data/test1566
index e6f81711d..cc3ac474a 100644
--- a/tests/data/test1566
+++ b/tests/data/test1566
@@ -35,7 +35,7 @@ http
http://%HOSTIP:%HTTPPORT/1566 -o log/output1566 --etag-compare log/etag1566
</command>
<file name="log/etag1566">
-123456
+"123456"
</file>
<file1 name="log/output1566">
downloaded already
diff --git a/tests/data/test339 b/tests/data/test339
index cd6e49892..8da212e55 100644
--- a/tests/data/test339
+++ b/tests/data/test339
@@ -14,7 +14,7 @@ Server: fakeit/0.9 fakeitbad/1.0
Transfer-Encoding: chunked
Trailer: chunky-trailer
Connection: mooo
-ETag: "asdf"
+ETag: W/"asdf"
40
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@@ -56,7 +56,7 @@ Accept: */*
</protocol>
<file name="log/etag339">
-asdf
+W/"asdf"
</file>
</verify>
diff --git a/tests/data/test342 b/tests/data/test342
index 95297ba50..75295cfa8 100644
--- a/tests/data/test342
+++ b/tests/data/test342
@@ -34,7 +34,7 @@ http
Check if --etag-compare set correct etag in header
</name>
<file name="log/etag342">
-21025-dc7-39462498
+"21025-dc7-39462498"
</file>
<command>
http://%HOSTIP:%HTTPPORT/342 --etag-compare log/etag342
diff --git a/tests/data/test343 b/tests/data/test343
index e55a181d8..5d877827f 100644
--- a/tests/data/test343
+++ b/tests/data/test343
@@ -34,7 +34,7 @@ http
Both --etag-compare and --etag-save to save new Etag
</name>
<file name="log/etag343">
-21025-dc7-39462498
+"21025-dc7-39462498"
</file>
<command>
http://%HOSTIP:%HTTPPORT/343 --etag-compare log/etag343 --etag-save log/out343
@@ -55,7 +55,7 @@ If-None-Match: "21025-dc7-39462498"
</protocol>
<file name="log/out343">
-21025-dc7-11111
+"21025-dc7-11111"
</file>
</verify>
</testcase>
diff --git a/tests/data/test344 b/tests/data/test344
index 054d0351b..2b730d524 100644
--- a/tests/data/test344
+++ b/tests/data/test344
@@ -52,7 +52,7 @@ If-None-Match: ""
</protocol>
<file name="log/etag344">
-21025-dc7-11111
+"21025-dc7-11111"
</file>
</verify>
</testcase>
diff --git a/tests/data/test345 b/tests/data/test345
index 135e0c26a..c30c06de9 100644
--- a/tests/data/test345
+++ b/tests/data/test345
@@ -34,7 +34,7 @@ http
Both --etag-compare and -save store new Etag using one pre-existing file
</name>
<file name="log/etag345">
-21025-dc7-39462498
+"21025-dc7-39462498"
</file>
<command>
http://%HOSTIP:%HTTPPORT/345 --etag-compare log/etag345 --etag-save log/etag345
@@ -55,7 +55,7 @@ If-None-Match: "21025-dc7-39462498"
</protocol>
<file name="log/etag345">
-21025-dc7-11111
+"21025-dc7-11111"
</file>
</verify>
</testcase>
diff --git a/tests/data/test339 b/tests/data/test347
similarity index 80%
copy from tests/data/test339
copy to tests/data/test347
index cd6e49892..702c270f9 100644
--- a/tests/data/test339
+++ b/tests/data/test347
@@ -14,7 +14,7 @@ Server: fakeit/0.9 fakeitbad/1.0
Transfer-Encoding: chunked
Trailer: chunky-trailer
Connection: mooo
-ETag: "asdf"
+ETag:
40
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@@ -36,10 +36,10 @@ chunky-trailer: header data
http
</server>
<name>
-Check if --etag-save saved correct etag to a file
+--etag-save with blank incoming header
</name>
<command>
-http://%HOSTIP:%HTTPPORT/339 --etag-save log/etag339
+http://%HOSTIP:%HTTPPORT/347 --etag-save log/etag347
</command>
</client>
@@ -50,13 +50,12 @@ http://%HOSTIP:%HTTPPORT/339 --etag-save log/etag339
^User-Agent:.*
</strip>
<protocol>
-GET /339 HTTP/1.1
+GET /347 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
</protocol>
-<file name="log/etag339">
-asdf
+<file name="log/etag347">
</file>
</verify>
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnurl] 28/411: winbuild/README.md: make <options> visible, (continued)
- [gnurl] 28/411: winbuild/README.md: make <options> visible, gnunet, 2021/01/12
- [gnurl] 31/411: git: ignore libtests in 3XXX area, gnunet, 2021/01/12
- [gnurl] 26/411: lib1560: verify "redirect" to double-slash leading URL, gnunet, 2021/01/12
- [gnurl] 17/411: sftp: add the option CURLKHSTAT_FINE_REPLACE, gnunet, 2021/01/12
- [gnurl] 19/411: curl: add --output-dir, gnunet, 2021/01/12
- [gnurl] 30/411: doh: add error message for DOH_DNS_NAME_TOO_LONG, gnunet, 2021/01/12
- [gnurl] 29/411: ngtcp2: adapt to the new pkt_info arguments, gnunet, 2021/01/12
- [gnurl] 16/411: RELEASE-NOTES: synced, gnunet, 2021/01/12
- [gnurl] 24/411: multi: implement wait using winsock events, gnunet, 2021/01/12
- [gnurl] 12/411: setopt: if the buffer exists, refuse the new BUFFERSIZE, gnunet, 2021/01/12
- [gnurl] 13/411: etag: save and use the full received contents,
gnunet <=
- [gnurl] 27/411: winbuild: convert the instruction text to README.md, gnunet, 2021/01/12
- [gnurl] 15/411: checksrc: verify do-while and spaces between the braces, gnunet, 2021/01/12
- [gnurl] 59/411: docs: add description about CI platforms to CONTRIBUTE.md, gnunet, 2021/01/12
- [gnurl] 67/411: curl.1: add see also no-progress-meter on two spots, gnunet, 2021/01/12
- [gnurl] 41/411: docs/libcurl: update "Added in" version for curl_easy_option*, gnunet, 2021/01/12
- [gnurl] 35/411: openssl: Fix wincrypt symbols conflict with BoringSSL, gnunet, 2021/01/12
- [gnurl] 18/411: configure: fix pkg-config detecting wolfssl, gnunet, 2021/01/12
- [gnurl] 32/411: schannel: fix memory leak when using get_cert_location, gnunet, 2021/01/12
- [gnurl] 10/411: CURLE_PROXY: new error code, gnunet, 2021/01/12
- [gnurl] 43/411: buildconf: invoke 'autoreconf -fi' instead, gnunet, 2021/01/12