]> granicus.if.org Git - curl/commitdiff
FILE: fix CURLOPT_NOBODY and CURLOPT_HEADER output
authorDaniel Stenberg <daniel@haxx.se>
Thu, 4 Oct 2018 21:53:32 +0000 (23:53 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 8 Oct 2018 06:35:40 +0000 (08:35 +0200)
Now FILE transfers send headers to the header callback like HTTP and
other protocols. Also made curl_easy_getinfo(...CURLINFO_PROTOCOL...)
work for FILE in the callbacks.

Makes "curl -i file://.." and "curl -I file://.." work like before
again. Applied the bold header logic to them too.

Regression from c1c2762 (7.61.0)

Reported-by: Shaun Jackman
Fixes #3083
Closes #3101

33 files changed:
lib/file.c
lib/getinfo.c
lib/url.c
src/tool_cb_hdr.c
tests/data/test1016
tests/data/test1017
tests/data/test1018
tests/data/test1019
tests/data/test1020
tests/data/test1029
tests/data/test1146
tests/data/test1220
tests/data/test200
tests/data/test2000
tests/data/test2001
tests/data/test2002
tests/data/test2003
tests/data/test2004
tests/data/test2006
tests/data/test2007
tests/data/test2008
tests/data/test2009
tests/data/test2010
tests/data/test202
tests/data/test203
tests/data/test204
tests/data/test205
tests/data/test2070
tests/data/test2071
tests/data/test2072
tests/data/test210
tests/data/test231
tests/data/test288

index 3cfa0e703862b41e07a9b12d35734dbfc04492b5..722b55e9d2dea7ae0652fff33bcd8c1e50435823 100644 (file)
@@ -386,7 +386,6 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
 
   *done = TRUE; /* unconditionally */
 
-  Curl_initinfo(data);
   Curl_pgrsStartNow(data);
 
   if(data->set.upload)
@@ -413,21 +412,18 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
     }
   }
 
-  /* If we have selected NOBODY and HEADER, it means that we only want file
-     information. Which for FILE can't be much more than the file size and
-     date. */
-  if(data->set.opt_no_body && data->set.include_header && fstated) {
+  if(fstated) {
     time_t filetime;
     struct tm buffer;
     const struct tm *tm = &buffer;
     char header[80];
     snprintf(header, sizeof(header),
              "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size);
-    result = Curl_client_write(conn, CLIENTWRITE_BOTH, header, 0);
+    result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
     if(result)
       return result;
 
-    result = Curl_client_write(conn, CLIENTWRITE_BOTH,
+    result = Curl_client_write(conn, CLIENTWRITE_HEADER,
                                (char *)"Accept-ranges: bytes\r\n", 0);
     if(result)
       return result;
@@ -439,19 +435,22 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
 
     /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
     snprintf(header, sizeof(header),
-             "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
+             "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n%s",
              Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
              tm->tm_mday,
              Curl_month[tm->tm_mon],
              tm->tm_year + 1900,
              tm->tm_hour,
              tm->tm_min,
-             tm->tm_sec);
-    result = Curl_client_write(conn, CLIENTWRITE_BOTH, header, 0);
-    if(!result)
-      /* set the file size to make it available post transfer */
-      Curl_pgrsSetDownloadSize(data, expected_size);
-    return result;
+             tm->tm_sec,
+             data->set.opt_no_body ? "": "\r\n");
+    result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
+    if(result)
+      return result;
+    /* set the file size to make it available post transfer */
+    Curl_pgrsSetDownloadSize(data, expected_size);
+    if(data->set.opt_no_body)
+      return result;
   }
 
   /* Check whether file range has been specified */
index 14b456274a74da7e8ef3a81837e89342c11f61aa..54c2c2f1cb6b277cd2c73198e019b025c474669f 100644 (file)
@@ -85,7 +85,6 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
 #ifdef USE_SSL
   Curl_ssl_free_certinfo(data);
 #endif
-
   return CURLE_OK;
 }
 
index f152319e7a62767a4ac311922846aa6eb7df1c5f..cde51186c3ff28fcd9bf61258343f06a6f16f66a 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3745,6 +3745,7 @@ static CURLcode create_conn(struct Curl_easy *data,
     /* this is supposed to be the connect function so we better at least check
        that the file is present here! */
     DEBUGASSERT(conn->handler->connect_it);
+    Curl_persistconninfo(conn);
     result = conn->handler->connect_it(conn, &done);
 
     /* Setup a "faked" transfer that'll do nothing */
index 04bc7e17bb83eb515bd1f70b223945dbcb8bc7bf..f0988228429f0106a5cd1e8d8d34b07ca6a1f5a3 100644 (file)
@@ -158,8 +158,9 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
   }
 
   if(hdrcbdata->config->show_headers &&
-     (protocol & (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP))) {
-    /* bold headers only happen for HTTP(S) and RTSP */
+    (protocol &
+     (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP|CURLPROTO_FILE))) {
+    /* bold headers only for selected protocols */
     char *value = NULL;
 
     if(!outs->stream && !tool_create_output_file(outs, FALSE))
index b404cacb61a0ed9b8ea1bc8d65c05208ebe687bd..4927f9eaa8f9bd03c9e5fc6ef98e5fa0baa9cd5b 100644 (file)
@@ -22,7 +22,7 @@ file
  <name>
 X-Y range on a file:// URL to stdout
  </name>
- <command>
+<command option="no-include">
 -r 1-4 file://localhost/%PWD/log/test1016.txt 
 </command>
 <file name="log/test1016.txt">
index 6fbc38ab2eb253b288d354159db6a67dd11694a3..cfdd80f9e2a5b63426c9f9f4d2f39a58ae946275 100644 (file)
@@ -23,7 +23,7 @@ file
  <name>
 0-Y range on a file:// URL to stdout
  </name>
- <command>
+<command option="no-include">
 -r 0-3 file://localhost/%PWD/log/test1017.txt 
 </command>
 <file name="log/test1017.txt">
index 28a7027d9e0c99e854416a5174c22ad3f6ed5d19..57487014fb35623ea836f62d27bf37bac756abf8 100644 (file)
@@ -22,7 +22,7 @@ file
  <name>
 X-X range on a file:// URL to stdout
  </name>
- <command>
+<command option="no-include">
 -r 4-4 file://localhost/%PWD/log/test1018.txt 
 </command>
 <file name="log/test1018.txt">
index 4d9872a2d0d044aeb2176b6fa707c9525df9d9e6..054e38d5d72d7ecd8cb9d55ac80f048a11f44dd2 100644 (file)
@@ -23,7 +23,7 @@ file
  <name>
 X- range on a file:// URL to stdout
  </name>
- <command>
+<command option="no-include">
 -r 7- file://localhost/%PWD/log/test1019.txt 
 </command>
 <file name="log/test1019.txt">
index 61032fb1787b246dedbb16363e08f8ded0d46262..8e03a1758b22f0ac357c820cf0f9e778d6eb0c36 100644 (file)
@@ -23,7 +23,7 @@ file
  <name>
 -Y range on a file:// URL to stdout
  </name>
- <command>
+<command option="no-include">
 -r -9 file://localhost/%PWD/log/test1020.txt 
 </command>
 <file name="log/test1020.txt">
index 2ffc7c64ae7394d6a5d5cf33b149e5b5999b04cd..c77209cad862ee14006e698d75eb8803983c39ea 100644 (file)
@@ -29,7 +29,7 @@ http
  <name>
 HTTP Location: and 'redirect_url' check
  </name>
- <command>
+<command>
 http://%HOSTIP:%HTTPPORT/we/want/our/1029 -w '%{redirect_url}\n'
 </command>
 </client>
index 43f33b79306075f7c0cf59ef90a30b909ce8472b..636748ee5ce2f395f1aa56f42bfc357009ee1ab2 100644 (file)
@@ -24,7 +24,7 @@ file
 <name>
 --proto-default file
 </name>
-<command>
+<command option="no-include">
 --proto-default file %PWD/log/test1146.txt
 </command>
 <file name="log/test1146.txt">
index 959abbf7094014f84e8b1a79ab58a2bd87317862..6752eb5804eb40e55c2336d87624e1deb0f604c9 100644 (file)
@@ -20,7 +20,7 @@ file
  <name>
 file:// URLs with query string
  </name>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/test1220.txt?a_query=foobar#afragment
 </command>
 <file name="log/test1220.txt">
index 8be1de0c747490bf87114e9a18b7872f584cc478..c27f7c095d22905c25c3cd4b2b871d8f847131ff 100644 (file)
@@ -23,7 +23,7 @@ file
  <name>
 basic file:// file
  </name>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/test200.txt
 </command>
 <file name="log/test200.txt">
index d3edb16e5a6d887c0cea6d4083b8fdb5807b4904..db1ba1330482e43a5a7068a12505f2b9349226c1 100644 (file)
@@ -31,7 +31,7 @@ file
  <name>
 FTP RETR followed by FILE
  </name>
- <command>
+<command option="no-include">
 ftp://%HOSTIP:%FTPPORT/2000 file://localhost/%PWD/log/test2000.txt
 </command>
 <file name="log/test2000.txt">
index 68c0df7841f92fbdb3b124ab55a699e775feb71c..88a258ebb838b1153af2bba0d628d64c0fe57e80 100644 (file)
@@ -48,7 +48,7 @@ file
  <name>
 HTTP GET followed by FTP RETR followed by FILE
  </name>
- <command>
+<command option="no-include">
 http://%HOSTIP:%HTTPPORT/20010001 ftp://%HOSTIP:%FTPPORT/20010002 file://localhost/%PWD/log/test2001.txt
 </command>
 <file name="log/test2001.txt">
@@ -81,17 +81,6 @@ RETR 20010002
 QUIT\r
 </protocol>
 <stdout>
-HTTP/1.1 200 OK\r
-Date: Thu, 09 Nov 2010 14:49:00 GMT\r
-Server: test-server/fake\r
-Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT\r
-ETag: "21025-dc7-39462498"\r
-Accept-Ranges: bytes\r
-Content-Length: 6\r
-Connection: close\r
-Content-Type: text/html\r
-Funny-head: yesyes\r
-\r
 -foo-
 data
     to
index db96bfea8035c0bce0045520404b6eb1ecd6e3aa..6dd2f9310a15a9c7c292fb9c648bb557c4cf3d60 100644 (file)
@@ -57,7 +57,7 @@ tftp
  <name>
 HTTP GET followed by FTP RETR followed by FILE followed by TFTP RRQ
  </name>
- <command>
+<command option="no-include">
 http://%HOSTIP:%HTTPPORT/20020001 ftp://%HOSTIP:%FTPPORT/20020002 file://localhost/%PWD/log/test2002.txt tftp://%HOSTIP:%TFTPPORT//20020003
 </command>
 <file name="log/test2002.txt">
@@ -96,17 +96,6 @@ filename: /20020003
 QUIT\r
 </protocol>
 <stdout>
-HTTP/1.1 200 OK\r
-Date: Thu, 09 Nov 2010 14:49:00 GMT\r
-Server: test-server/fake\r
-Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT\r
-ETag: "21025-dc7-39462498"\r
-Accept-Ranges: bytes\r
-Content-Length: 6\r
-Connection: close\r
-Content-Type: text/html\r
-Funny-head: yesyes\r
-\r
 -foo-
 data
     to
index 59a743f8577cccb7cec31fb5a7ceb39f95b87177..09bee8e22066956ec4101d936c1adbcfb8c5e1e7 100644 (file)
@@ -57,8 +57,8 @@ tftp
  <name>
 HTTP GET followed by FTP RETR followed by FILE followed by TFTP RRQ then again in reverse order
  </name>
- <command>
-http://%HOSTIP:%HTTPPORT/20030001 ftp://%HOSTIP:%FTPPORT/20030002 file://localhost/%PWD/log/test2003.txt tftp://%HOSTIP:%TFTPPORT//20030003 tftp://%HOSTIP:%TFTPPORT//20030003 file://localhost/%PWD/log/test2003.txt ftp://%HOSTIP:%FTPPORT/20030002 http://%HOSTIP:%HTTPPORT/20030001 
+<command option="no-include">
+http://%HOSTIP:%HTTPPORT/20030001 ftp://%HOSTIP:%FTPPORT/20030002 file://localhost/%PWD/log/test2003.txt tftp://%HOSTIP:%TFTPPORT//20030003 tftp://%HOSTIP:%TFTPPORT//20030003 file://localhost/%PWD/log/test2003.txt ftp://%HOSTIP:%FTPPORT/20030002 http://%HOSTIP:%HTTPPORT/20030001
 </command>
 <file name="log/test2003.txt">
 foo
@@ -109,17 +109,6 @@ Accept: */*
 QUIT\r
 </protocol>
 <stdout>
-HTTP/1.1 200 OK\r
-Date: Thu, 09 Nov 2010 14:49:00 GMT\r
-Server: test-server/fake\r
-Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT\r
-ETag: "21025-dc7-39462498"\r
-Accept-Ranges: bytes\r
-Content-Length: 6\r
-Connection: close\r
-Content-Type: text/html\r
-Funny-head: yesyes\r
-\r
 -foo-
 data
     to
@@ -151,17 +140,6 @@ data
 that FTP
 works
   so does it?
-HTTP/1.1 200 OK\r
-Date: Thu, 09 Nov 2010 14:49:00 GMT\r
-Server: test-server/fake\r
-Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT\r
-ETag: "21025-dc7-39462498"\r
-Accept-Ranges: bytes\r
-Content-Length: 6\r
-Connection: close\r
-Content-Type: text/html\r
-Funny-head: yesyes\r
-\r
 -foo-
 </stdout>
 </verify>
index 4773f69032677de70f9dc739908401107d1a268b..b17890b0f6eb768fb560f81987b10a4107e60926 100644 (file)
@@ -29,7 +29,7 @@ sftp
  <name>
 TFTP RRQ followed by SFTP retrieval followed by FILE followed by SCP retrieval then again in reverse order
  </name>
- <command>
+<command option="no-include">
 --key curl_client_key --pubkey curl_client_key.pub -u %USER: tftp://%HOSTIP:%TFTPPORT//2004 sftp://%HOSTIP:%SSHPORT%POSIX_PWD/log/test2004.txt file://localhost/%PWD/log/test2004.txt scp://%HOSTIP:%SSHPORT%POSIX_PWD/log/test2004.txt file://localhost/%PWD/log/test2004.txt sftp://%HOSTIP:%SSHPORT%POSIX_PWD/log/test2004.txt tftp://%HOSTIP:%TFTPPORT//2004 --insecure
 </command>
 <file name="log/test2004.txt">
index e25556fccdaf5547f8562db70c0e9959b00519c0..3acbdaee2e049e649faa504d260d4198375e9ad5 100644 (file)
@@ -4,6 +4,7 @@
 Metalink
 HTTP
 HTTP GET
+FILE
 </keywords>
 </info>
 
@@ -85,6 +86,10 @@ Accept: */*
 Some data delivered from an HTTP resource
 </file1>
 <file2 name="log/heads2006">
+Content-Length: 496\r
+Accept-ranges: bytes\r
+
+\r
 HTTP/1.1 200 OK
 Date: Thu, 21 Jun 2012 14:49:01 GMT
 Server: test-server/fake
@@ -105,6 +110,9 @@ Metalink: fetching (log/download2006) from (http://%HOSTIP:%HTTPPORT/2006) OK
 Metalink: validating (log/download2006)...
 Metalink: validating (log/download2006) [sha-256] OK
 </file4>
+<stripfile2>
+s/Last-Modified:.*//
+</stripfile2>
 <stripfile4>
 $_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i))
 </stripfile4>
index cc4bd8c327431a8334df2d669882878f72d6b884..b169c49060beca1462284ceb3defe608e0ca72df 100644 (file)
@@ -5,6 +5,7 @@ Metalink
 HTTP
 HTTP GET
 -J
+FILE
 </keywords>
 </info>
 
@@ -85,7 +86,14 @@ Accept: */*
 <file1 name="log/download2007">
 Something delivered from an HTTP resource
 </file1>
+<stripfile2>
+s/Last-Modified:.*//
+</stripfile2>
 <file2 name="log/heads2007">
+Content-Length: 496\r
+Accept-ranges: bytes\r
+
+\r
 HTTP/1.1 200 OK
 Date: Thu, 21 Jun 2012 14:50:02 GMT
 Server: test-server/fake
index 58437926070d2f71444e27a2924b731d5b26564b..012f221c4786b1911ee2a5d4f729e85da2bf1b05 100644 (file)
@@ -4,6 +4,7 @@
 Metalink
 HTTP
 HTTP GET
+FILE
 </keywords>
 </info>
 
@@ -77,7 +78,14 @@ Accept: */*
 <file1 name="log/download2008">
 Some stuff delivered from an HTTP resource
 </file1>
+<stripfile2>
+s/Last-Modified:.*//
+</stripfile2>
 <file2 name="log/heads2008">
+Content-Length: 496\r
+Accept-ranges: bytes\r
+
+\r
 HTTP/1.1 200 OK
 Date: Thu, 21 Jun 2012 15:23:48 GMT
 Server: test-server/fake
index 84482ce89031e3b1d9ac82371fe02572bb7b6fce..b0e5c6c66ecf907cb161ed450da3a0536c49aed6 100644 (file)
@@ -5,6 +5,7 @@ Metalink
 HTTP
 HTTP GET
 -J
+FILE
 </keywords>
 </info>
 
@@ -78,7 +79,14 @@ Accept: */*
 <file1 name="log/download2009">
 Some contents delivered from an HTTP resource
 </file1>
+<stripfile2>
+s/Last-Modified:.*//
+</stripfile2>
 <file2 name="log/heads2009">
+Content-Length: 496\r
+Accept-ranges: bytes\r
+
+\r
 HTTP/1.1 200 OK
 Date: Thu, 21 Jun 2012 16:27:17 GMT
 Server: test-server/fake
index 91a83f4dc83ccb33716ce3416511156fddcebb8f..33bb309ebf0fd19f8033a7b1db46cd581c990f42 100644 (file)
@@ -4,6 +4,7 @@
 Metalink
 HTTP
 HTTP GET
+FILE
 </keywords>
 </info>
 
@@ -77,7 +78,14 @@ Accept: */*
 <file1 name="log/download2010">
 Contents delivered from an HTTP resource
 </file1>
+<stripfile2>
+s/Last-Modified:.*//
+</stripfile2>
 <file2 name="log/heads2010">
+Content-Length: 496\r
+Accept-ranges: bytes\r
+
+\r
 HTTP/1.1 200 OK
 Date: Thu, 21 Jun 2012 17:37:27 GMT
 Server: test-server/fake
index f863ec507cda261fb02f4ca994279ea35100d955..0b324b1d801f544897a7d39c4dcf9580c4a7c96e 100644 (file)
@@ -19,7 +19,7 @@ file
  <name>
 two file:// URLs to stdout
  </name>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/test202.txt FILE://localhost/%PWD/log/test202.txt
 </command>
 <file name="log/test202.txt">
index 366cc2cd09b7f26fdb26fb0f5c07c453212f0e54..393842656f0c1e00f2d8108e304a9f777d677171 100644 (file)
@@ -24,7 +24,7 @@ file
  <name>
 file:/path URL with a single slash
  </name>
- <command>
+<command option="no-include">
 file:%PWD/log/test203.txt
 </command>
 <file name="log/test203.txt">
index 9cc7b01541438032fab621301717b49142b4c6fb..0ed94512f934d287b92fdc4f1d9b372285edf0fd 100644 (file)
@@ -15,7 +15,7 @@ file
  <name>
 "upload" with file://
  </name>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/result204.txt -T log/upload204.txt
 </command>
 <file name="log/upload204.txt">
index 4af93f64234946db7f77633a75360da4df40d2f0..f83c5315781f1eed6c71cb9883b515ab91846dbb 100644 (file)
@@ -16,7 +16,7 @@ file
  <name>
 "upload" with file://
  </name>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/nonexisting/result205.txt -T log/upload205.txt
 </command>
 <file name="log/upload205.txt">
index bc3898ab315d6e2a07dcc4da9345bcd167e5e7b3..655cd8a39f97b4b534ec05297c09804ca44c9cb8 100644 (file)
@@ -23,7 +23,7 @@ file
  <name>
 basic file:// file with no authority
  </name>
- <command>
+<command option="no-include">
 file:%PWD/log/test2070.txt
 </command>
 <file name="log/test2070.txt">
index 997dfffeb038098689523b25f62d99fa0f26b1a9..eddfa4df7bcb2b7f758b9b462f6b4a9e83796cc8 100644 (file)
@@ -23,7 +23,7 @@ file
  <name>
 basic file:// file with "127.0.0.1" hostname
  </name>
- <command>
+<command option="no-include">
 file://127.0.0.1/%PWD/log/test2070.txt
 </command>
 <file name="log/test2070.txt">
index cd26f22bd6354089ed214928a24b2f51c2cb0f19..1bab15888733ef1042fe029046bb07eec96a01f1 100644 (file)
@@ -23,7 +23,7 @@ file
 <name>
 file:// with unix path resolution behavior for the case of extra slashes
 </name>
-<command>
+<command option="no-include">
 file:////%PWD/log/test2072.txt
 </command>
 <precheck>
index e9045675446ca879e7099301c9c54d211b551f42..c6fb7030939630d78d7c89fae3bce1003d684a13 100644 (file)
@@ -22,7 +22,7 @@ ftp
  <name>
 Get two FTP files from the same remote dir: no second CWD
  </name>
- <command>
+<command option="no-include">
 ftp://%HOSTIP:%FTPPORT/a/path/210 ftp://%HOSTIP:%FTPPORT/a/path/210
 </command>
 <stdout>
index 6994957c12db7c83edc8f42c6d08c280ee1d364a..3d4bc7730184158c8d5fcdffc2d418bfffeb275e 100644 (file)
@@ -22,7 +22,7 @@ file
  <name>
 file:// with resume
  </name>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/test231.txt -C 10
 </command>
 <file name="log/test231.txt">
index ff4db6a472b7aa956bbc1941fd2b31f4fccf79f8..9f8f6e1219dd44c1fb607226dd9c0592cd8abe79 100644 (file)
@@ -30,7 +30,7 @@ file:// with (unsupported) proxy, authentication and range
 <setenv>
 all_proxy=http://fake:user@%HOSTIP:%HTTPPORT/
 </setenv>
- <command>
+<command option="no-include">
 file://localhost/%PWD/log/test288.txt
 </command>
 <file name="log/test288.txt">