]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: support --dump-header % to direct to stderr
authorDaniel Stenberg <daniel@haxx.se>
Sun, 4 Aug 2024 14:01:41 +0000 (16:01 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 4 Aug 2024 14:02:24 +0000 (16:02 +0200)
Similar to how --trace and --trace-ascii already do it.

Added test 1489 to verify

Closes #13992

docs/cmdline-opts/dump-header.md
src/tool_operate.c
tests/data/Makefile.am
tests/data/test1489 [new file with mode: 0644]

index 925e6da668a2b2c0717802f89c3845fc37d4adf6..81da38c4091acaf0d8dc073956fab82cb82293df 100644 (file)
@@ -19,8 +19,11 @@ Example:
 # `--dump-header`
 
 Write the received protocol headers to the specified file. If no headers are
-received, the use of this option creates an empty file. Specify `-` as file
-name (a single minus) to have it written to stdout.
+received, the use of this option creates an empty file. Specify `-` as
+filename (a single minus) to have it written to stdout.
+
+Starting in curl 8.10.0, specify `%` (a single percent sign) as filename
+writes the output to stderr.
 
 When used in FTP, the FTP server response lines are considered being "headers"
 and thus are saved there.
index 017119eab7a51bf054d7da9d0acacc48514621b5..caade1346ad808ef4cbac26989d30dea141921d4 100644 (file)
@@ -1057,7 +1057,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         /* Single header file for all URLs */
         if(config->headerfile) {
           /* open file for output: */
-          if(strcmp(config->headerfile, "-")) {
+          if(!strcmp(config->headerfile, "%")) {
+            heads->stream = stderr;
+            /* use binary mode for protocol header output */
+            set_binmode(heads->stream);
+          }
+          else if(strcmp(config->headerfile, "-")) {
             FILE *newfile;
 
             /*
index d5ed7af56e95c19260ebf93f798b3f6316ab2056..9c1ca69eff1cb094b9ff698447787e506a8404b9 100644 (file)
@@ -192,7 +192,7 @@ test1455 test1456 test1457 test1458 test1459 test1460 test1461 test1462 \
 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test1470 \
 test1471 test1472 test1473 test1474 test1475 test1476 test1477 test1478 \
 test1479 test1480 test1481 test1482 test1483 test1484 test1485 test1486 \
-test1487 test1488 \
+test1487 test1488 test1489 \
 \
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
 test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
diff --git a/tests/data/test1489 b/tests/data/test1489
new file mode 100644 (file)
index 0000000..e1460bf
--- /dev/null
@@ -0,0 +1,66 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data crlf="yes" nocheck="yes">
+HTTP/1.1 200 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-39462498"
+Accept-Ranges: bytes
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Funny-head: yesyes
+
+-foo-
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+-D sent to stderr
+</name>
+<command option="no-include">
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER -D % -s
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol crlf="yes">
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+
+</protocol>
+<stderr crlf="yes">
+HTTP/1.1 200 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-39462498"
+Accept-Ranges: bytes
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Funny-head: yesyes
+
+</stderr>
+</verify>
+</testcase>