]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: add %header{name} support in -w handling
authorDaniel Stenberg <daniel@haxx.se>
Thu, 17 Mar 2022 15:32:45 +0000 (16:32 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 22 Mar 2022 07:24:25 +0000 (08:24 +0100)
Outputs the response header 'name'

docs/cmdline-opts/write-out.d
src/tool_writeout.c

index 35ab41a22b396b723d706fb4c5c4a5a9c284abe1..6d8ed44925ffb3a5ae458da18d55f2fb5249c4f6 100644 (file)
@@ -22,6 +22,10 @@ output a newline by using \\n, a carriage return with \\r and a tab space with
 The output will be written to standard output, but this can be switched to
 standard error by using %{stderr}.
 
+You can also access HTTP headers of the most recent request done, with the
+help of \fB%header{name}\fP where \fBname\fP is the case insensitive name of
+the header (without trailing colon). Added in curl 7.83.0.
+
 .B NOTE:
 The %-symbol is a special symbol in the win32-environment, where all
 occurrences of % must be doubled when using this option.
index 5b22a1a9cb991fabdb6db6f8b7699e5d65a3520a..c2e4095530aaee9f501b12b24be797a5b823ca1f 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -380,6 +380,20 @@ void ourWriteOut(const char *writeinfo, struct per_transfer *per,
           ptr = end + 1; /* pass the end */
           *end = keepit;
         }
+        else if(!strncmp("header{", &ptr[1], 7)) {
+          ptr += 8;
+          end = strchr(ptr, '}');
+          if(end) {
+            struct curl_header *header;
+            *end = 0;
+            if(CURLHE_OK == curl_easy_header(per->curl, ptr, 0, CURLH_HEADER,
+                                             -1, &header))
+              fputs(header->value, stream);
+            ptr = end + 1; /* pass the end */
+          }
+          else
+            fputs("%header{", stream);
+        }
         else {
           /* illegal syntax, then just output the characters that are used */
           fputc('%', stream);