diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-08-20 00:34:44 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-08-24 10:02:41 +0200 |
commit | 98c94596f5928840177b6bd3c7b0f0dd03a431af (patch) | |
tree | 280a4d57dffd2222c39c9e481b6bbbbd5adec397 /src/tool_cb_hdr.c | |
parent | bc3b5bcf87f9fe16514f8cfd84cded24a367ac95 (diff) | |
download | curl-98c94596f5928840177b6bd3c7b0f0dd03a431af.tar.gz |
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
Diffstat (limited to 'src/tool_cb_hdr.c')
-rw-r--r-- | src/tool_cb_hdr.c | 56 |
1 files changed, 15 insertions, 41 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); } /* |