summaryrefslogtreecommitdiff
path: root/src/tool_cb_hdr.c
diff options
context:
space:
mode:
authornikita <nikita@NetBSD.org>2021-01-13 00:53:52 +0100
committernikita <nikita@NetBSD.org>2021-01-13 00:53:52 +0100
commit5b9f8acdda96cbaf7ec070db3ae9bdbe2a42f8eb (patch)
treed69e840805484efba1885154b855bf93409248cb /src/tool_cb_hdr.c
parent7bd28f37397837d72302550e43d95060413e9eb8 (diff)
parente052859759b34d0e05ce0f17244873e5cd7b457b (diff)
downloadgnurl-5b9f8acdda96cbaf7ec070db3ae9bdbe2a42f8eb.tar.gz
gnurl-5b9f8acdda96cbaf7ec070db3ae9bdbe2a42f8eb.tar.bz2
gnurl-5b9f8acdda96cbaf7ec070db3ae9bdbe2a42f8eb.zip
Merge tag 'curl-7_74_0'
7.74.0
Diffstat (limited to 'src/tool_cb_hdr.c')
-rw-r--r--src/tool_cb_hdr.c70
1 files changed, 27 insertions, 43 deletions
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c
index 5741f0aba..67ea10447 100644
--- a/src/tool_cb_hdr.c
+++ b/src/tool_cb_hdr.c
@@ -9,7 +9,7 @@
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at https://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
@@ -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);
}
/*
@@ -205,7 +179,17 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
if(!outs->stream && !tool_create_output_file(outs, per->config))
return failure;
}
-
+ if(hdrcbdata->config->writeout) {
+ char *value = memchr(ptr, ':', cb);
+ if(value) {
+ if(per->was_last_header_empty)
+ per->num_headers = 0;
+ per->was_last_header_empty = FALSE;
+ per->num_headers++;
+ }
+ else if(ptr[0] == '\r' || ptr[0] == '\n')
+ per->was_last_header_empty = TRUE;
+ }
if(hdrcbdata->config->show_headers &&
(protocol &
(CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP|CURLPROTO_FILE))) {