From: Daniel Stenberg Date: Sun, 4 Aug 2024 14:01:41 +0000 (+0200) Subject: tool_operate: support --dump-header % to direct to stderr X-Git-Tag: curl-8_10_0~403 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b1e4b4632447d0b20e77bbae2f22bd8258854db;p=thirdparty%2Fcurl.git tool_operate: support --dump-header % to direct to stderr Similar to how --trace and --trace-ascii already do it. Added test 1489 to verify Closes #13992 --- diff --git a/docs/cmdline-opts/dump-header.md b/docs/cmdline-opts/dump-header.md index 925e6da668..81da38c409 100644 --- a/docs/cmdline-opts/dump-header.md +++ b/docs/cmdline-opts/dump-header.md @@ -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. diff --git a/src/tool_operate.c b/src/tool_operate.c index 017119eab7..caade1346a 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -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; /* diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index d5ed7af56e..9c1ca69eff 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -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 index 0000000000..e1460bf5c7 --- /dev/null +++ b/tests/data/test1489 @@ -0,0 +1,66 @@ + + + +HTTP +HTTP GET + + + +# +# Server-side + + +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- + + + +# +# Client-side + + +http + + +-D sent to stderr + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER -D % -s + + + +# +# Verify data after the test has been "shot" + + +GET /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +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 + + + +