FILE: fix CURLOPT_NOBODY and CURLOPT_HEADER output

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
This commit is contained in:
Daniel Stenberg 2018-10-04 23:53:32 +02:00
parent b55e85d4ec
commit e50a2002bd
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
33 changed files with 82 additions and 86 deletions

View file

@ -386,7 +386,6 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
*done = TRUE; /* unconditionally */ *done = TRUE; /* unconditionally */
Curl_initinfo(data);
Curl_pgrsStartNow(data); Curl_pgrsStartNow(data);
if(data->set.upload) 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 if(fstated) {
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) {
time_t filetime; time_t filetime;
struct tm buffer; struct tm buffer;
const struct tm *tm = &buffer; const struct tm *tm = &buffer;
char header[80]; char header[80];
snprintf(header, sizeof(header), snprintf(header, sizeof(header),
"Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size); "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) if(result)
return result; return result;
result = Curl_client_write(conn, CLIENTWRITE_BOTH, result = Curl_client_write(conn, CLIENTWRITE_HEADER,
(char *)"Accept-ranges: bytes\r\n", 0); (char *)"Accept-ranges: bytes\r\n", 0);
if(result) if(result)
return 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" */ /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
snprintf(header, sizeof(header), 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], Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
tm->tm_mday, tm->tm_mday,
Curl_month[tm->tm_mon], Curl_month[tm->tm_mon],
tm->tm_year + 1900, tm->tm_year + 1900,
tm->tm_hour, tm->tm_hour,
tm->tm_min, tm->tm_min,
tm->tm_sec); tm->tm_sec,
result = Curl_client_write(conn, CLIENTWRITE_BOTH, header, 0); data->set.opt_no_body ? "": "\r\n");
if(!result) result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
/* set the file size to make it available post transfer */ if(result)
Curl_pgrsSetDownloadSize(data, expected_size); return 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 */ /* Check whether file range has been specified */

View file

@ -85,7 +85,6 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
#ifdef USE_SSL #ifdef USE_SSL
Curl_ssl_free_certinfo(data); Curl_ssl_free_certinfo(data);
#endif #endif
return CURLE_OK; return CURLE_OK;
} }

View file

@ -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 /* this is supposed to be the connect function so we better at least check
that the file is present here! */ that the file is present here! */
DEBUGASSERT(conn->handler->connect_it); DEBUGASSERT(conn->handler->connect_it);
Curl_persistconninfo(conn);
result = conn->handler->connect_it(conn, &done); result = conn->handler->connect_it(conn, &done);
/* Setup a "faked" transfer that'll do nothing */ /* Setup a "faked" transfer that'll do nothing */

View 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 && if(hdrcbdata->config->show_headers &&
(protocol & (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP))) { (protocol &
/* bold headers only happen for HTTP(S) and RTSP */ (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP|CURLPROTO_FILE))) {
/* bold headers only for selected protocols */
char *value = NULL; char *value = NULL;
if(!outs->stream && !tool_create_output_file(outs, FALSE)) if(!outs->stream && !tool_create_output_file(outs, FALSE))

View file

@ -22,7 +22,7 @@ file
<name> <name>
X-Y range on a file:// URL to stdout X-Y range on a file:// URL to stdout
</name> </name>
<command> <command option="no-include">
-r 1-4 file://localhost/%PWD/log/test1016.txt -r 1-4 file://localhost/%PWD/log/test1016.txt
</command> </command>
<file name="log/test1016.txt"> <file name="log/test1016.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
0-Y range on a file:// URL to stdout 0-Y range on a file:// URL to stdout
</name> </name>
<command> <command option="no-include">
-r 0-3 file://localhost/%PWD/log/test1017.txt -r 0-3 file://localhost/%PWD/log/test1017.txt
</command> </command>
<file name="log/test1017.txt"> <file name="log/test1017.txt">

View file

@ -22,7 +22,7 @@ file
<name> <name>
X-X range on a file:// URL to stdout X-X range on a file:// URL to stdout
</name> </name>
<command> <command option="no-include">
-r 4-4 file://localhost/%PWD/log/test1018.txt -r 4-4 file://localhost/%PWD/log/test1018.txt
</command> </command>
<file name="log/test1018.txt"> <file name="log/test1018.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
X- range on a file:// URL to stdout X- range on a file:// URL to stdout
</name> </name>
<command> <command option="no-include">
-r 7- file://localhost/%PWD/log/test1019.txt -r 7- file://localhost/%PWD/log/test1019.txt
</command> </command>
<file name="log/test1019.txt"> <file name="log/test1019.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
-Y range on a file:// URL to stdout -Y range on a file:// URL to stdout
</name> </name>
<command> <command option="no-include">
-r -9 file://localhost/%PWD/log/test1020.txt -r -9 file://localhost/%PWD/log/test1020.txt
</command> </command>
<file name="log/test1020.txt"> <file name="log/test1020.txt">

View file

@ -29,7 +29,7 @@ http
<name> <name>
HTTP Location: and 'redirect_url' check HTTP Location: and 'redirect_url' check
</name> </name>
<command> <command>
http://%HOSTIP:%HTTPPORT/we/want/our/1029 -w '%{redirect_url}\n' http://%HOSTIP:%HTTPPORT/we/want/our/1029 -w '%{redirect_url}\n'
</command> </command>
</client> </client>

View file

@ -24,7 +24,7 @@ file
<name> <name>
--proto-default file --proto-default file
</name> </name>
<command> <command option="no-include">
--proto-default file %PWD/log/test1146.txt --proto-default file %PWD/log/test1146.txt
</command> </command>
<file name="log/test1146.txt"> <file name="log/test1146.txt">

View file

@ -20,7 +20,7 @@ file
<name> <name>
file:// URLs with query string file:// URLs with query string
</name> </name>
<command> <command option="no-include">
file://localhost/%PWD/log/test1220.txt?a_query=foobar#afragment file://localhost/%PWD/log/test1220.txt?a_query=foobar#afragment
</command> </command>
<file name="log/test1220.txt"> <file name="log/test1220.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
basic file:// file basic file:// file
</name> </name>
<command> <command option="no-include">
file://localhost/%PWD/log/test200.txt file://localhost/%PWD/log/test200.txt
</command> </command>
<file name="log/test200.txt"> <file name="log/test200.txt">

View file

@ -31,7 +31,7 @@ file
<name> <name>
FTP RETR followed by FILE FTP RETR followed by FILE
</name> </name>
<command> <command option="no-include">
ftp://%HOSTIP:%FTPPORT/2000 file://localhost/%PWD/log/test2000.txt ftp://%HOSTIP:%FTPPORT/2000 file://localhost/%PWD/log/test2000.txt
</command> </command>
<file name="log/test2000.txt"> <file name="log/test2000.txt">

View file

@ -48,7 +48,7 @@ file
<name> <name>
HTTP GET followed by FTP RETR followed by FILE HTTP GET followed by FTP RETR followed by FILE
</name> </name>
<command> <command option="no-include">
http://%HOSTIP:%HTTPPORT/20010001 ftp://%HOSTIP:%FTPPORT/20010002 file://localhost/%PWD/log/test2001.txt http://%HOSTIP:%HTTPPORT/20010001 ftp://%HOSTIP:%FTPPORT/20010002 file://localhost/%PWD/log/test2001.txt
</command> </command>
<file name="log/test2001.txt"> <file name="log/test2001.txt">
@ -81,17 +81,6 @@ RETR 20010002
QUIT QUIT
</protocol> </protocol>
<stdout> <stdout>
HTTP/1.1 200 OK
Date: Thu, 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- -foo-
data data
to to

View file

@ -57,7 +57,7 @@ tftp
<name> <name>
HTTP GET followed by FTP RETR followed by FILE followed by TFTP RRQ HTTP GET followed by FTP RETR followed by FILE followed by TFTP RRQ
</name> </name>
<command> <command option="no-include">
http://%HOSTIP:%HTTPPORT/20020001 ftp://%HOSTIP:%FTPPORT/20020002 file://localhost/%PWD/log/test2002.txt tftp://%HOSTIP:%TFTPPORT//20020003 http://%HOSTIP:%HTTPPORT/20020001 ftp://%HOSTIP:%FTPPORT/20020002 file://localhost/%PWD/log/test2002.txt tftp://%HOSTIP:%TFTPPORT//20020003
</command> </command>
<file name="log/test2002.txt"> <file name="log/test2002.txt">
@ -96,17 +96,6 @@ filename: /20020003
QUIT QUIT
</protocol> </protocol>
<stdout> <stdout>
HTTP/1.1 200 OK
Date: Thu, 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- -foo-
data data
to to

View file

@ -57,8 +57,8 @@ tftp
<name> <name>
HTTP GET followed by FTP RETR followed by FILE followed by TFTP RRQ then again in reverse order HTTP GET followed by FTP RETR followed by FILE followed by TFTP RRQ then again in reverse order
</name> </name>
<command> <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 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> </command>
<file name="log/test2003.txt"> <file name="log/test2003.txt">
foo foo
@ -109,17 +109,6 @@ Accept: */*
QUIT QUIT
</protocol> </protocol>
<stdout> <stdout>
HTTP/1.1 200 OK
Date: Thu, 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- -foo-
data data
to to
@ -151,17 +140,6 @@ data
that FTP that FTP
works works
so does it? so does it?
HTTP/1.1 200 OK
Date: Thu, 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- -foo-
</stdout> </stdout>
</verify> </verify>

View file

@ -29,7 +29,7 @@ sftp
<name> <name>
TFTP RRQ followed by SFTP retrieval followed by FILE followed by SCP retrieval then again in reverse order TFTP RRQ followed by SFTP retrieval followed by FILE followed by SCP retrieval then again in reverse order
</name> </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 --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> </command>
<file name="log/test2004.txt"> <file name="log/test2004.txt">

View file

@ -4,6 +4,7 @@
Metalink Metalink
HTTP HTTP
HTTP GET HTTP GET
FILE
</keywords> </keywords>
</info> </info>
@ -85,6 +86,10 @@ Accept: */*
Some data delivered from an HTTP resource Some data delivered from an HTTP resource
</file1> </file1>
<file2 name="log/heads2006"> <file2 name="log/heads2006">
Content-Length: 496
Accept-ranges: bytes
HTTP/1.1 200 OK HTTP/1.1 200 OK
Date: Thu, 21 Jun 2012 14:49:01 GMT Date: Thu, 21 Jun 2012 14:49:01 GMT
Server: test-server/fake 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)...
Metalink: validating (log/download2006) [sha-256] OK Metalink: validating (log/download2006) [sha-256] OK
</file4> </file4>
<stripfile2>
s/Last-Modified:.*//
</stripfile2>
<stripfile4> <stripfile4>
$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) $_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i))
</stripfile4> </stripfile4>

View file

@ -5,6 +5,7 @@ Metalink
HTTP HTTP
HTTP GET HTTP GET
-J -J
FILE
</keywords> </keywords>
</info> </info>
@ -85,7 +86,14 @@ Accept: */*
<file1 name="log/download2007"> <file1 name="log/download2007">
Something delivered from an HTTP resource Something delivered from an HTTP resource
</file1> </file1>
<stripfile2>
s/Last-Modified:.*//
</stripfile2>
<file2 name="log/heads2007"> <file2 name="log/heads2007">
Content-Length: 496
Accept-ranges: bytes
HTTP/1.1 200 OK HTTP/1.1 200 OK
Date: Thu, 21 Jun 2012 14:50:02 GMT Date: Thu, 21 Jun 2012 14:50:02 GMT
Server: test-server/fake Server: test-server/fake

View file

@ -4,6 +4,7 @@
Metalink Metalink
HTTP HTTP
HTTP GET HTTP GET
FILE
</keywords> </keywords>
</info> </info>
@ -77,7 +78,14 @@ Accept: */*
<file1 name="log/download2008"> <file1 name="log/download2008">
Some stuff delivered from an HTTP resource Some stuff delivered from an HTTP resource
</file1> </file1>
<stripfile2>
s/Last-Modified:.*//
</stripfile2>
<file2 name="log/heads2008"> <file2 name="log/heads2008">
Content-Length: 496
Accept-ranges: bytes
HTTP/1.1 200 OK HTTP/1.1 200 OK
Date: Thu, 21 Jun 2012 15:23:48 GMT Date: Thu, 21 Jun 2012 15:23:48 GMT
Server: test-server/fake Server: test-server/fake

View file

@ -5,6 +5,7 @@ Metalink
HTTP HTTP
HTTP GET HTTP GET
-J -J
FILE
</keywords> </keywords>
</info> </info>
@ -78,7 +79,14 @@ Accept: */*
<file1 name="log/download2009"> <file1 name="log/download2009">
Some contents delivered from an HTTP resource Some contents delivered from an HTTP resource
</file1> </file1>
<stripfile2>
s/Last-Modified:.*//
</stripfile2>
<file2 name="log/heads2009"> <file2 name="log/heads2009">
Content-Length: 496
Accept-ranges: bytes
HTTP/1.1 200 OK HTTP/1.1 200 OK
Date: Thu, 21 Jun 2012 16:27:17 GMT Date: Thu, 21 Jun 2012 16:27:17 GMT
Server: test-server/fake Server: test-server/fake

View file

@ -4,6 +4,7 @@
Metalink Metalink
HTTP HTTP
HTTP GET HTTP GET
FILE
</keywords> </keywords>
</info> </info>
@ -77,7 +78,14 @@ Accept: */*
<file1 name="log/download2010"> <file1 name="log/download2010">
Contents delivered from an HTTP resource Contents delivered from an HTTP resource
</file1> </file1>
<stripfile2>
s/Last-Modified:.*//
</stripfile2>
<file2 name="log/heads2010"> <file2 name="log/heads2010">
Content-Length: 496
Accept-ranges: bytes
HTTP/1.1 200 OK HTTP/1.1 200 OK
Date: Thu, 21 Jun 2012 17:37:27 GMT Date: Thu, 21 Jun 2012 17:37:27 GMT
Server: test-server/fake Server: test-server/fake

View file

@ -19,7 +19,7 @@ file
<name> <name>
two file:// URLs to stdout two file:// URLs to stdout
</name> </name>
<command> <command option="no-include">
file://localhost/%PWD/log/test202.txt FILE://localhost/%PWD/log/test202.txt file://localhost/%PWD/log/test202.txt FILE://localhost/%PWD/log/test202.txt
</command> </command>
<file name="log/test202.txt"> <file name="log/test202.txt">

View file

@ -24,7 +24,7 @@ file
<name> <name>
file:/path URL with a single slash file:/path URL with a single slash
</name> </name>
<command> <command option="no-include">
file:%PWD/log/test203.txt file:%PWD/log/test203.txt
</command> </command>
<file name="log/test203.txt"> <file name="log/test203.txt">

View file

@ -15,7 +15,7 @@ file
<name> <name>
"upload" with file:// "upload" with file://
</name> </name>
<command> <command option="no-include">
file://localhost/%PWD/log/result204.txt -T log/upload204.txt file://localhost/%PWD/log/result204.txt -T log/upload204.txt
</command> </command>
<file name="log/upload204.txt"> <file name="log/upload204.txt">

View file

@ -16,7 +16,7 @@ file
<name> <name>
"upload" with file:// "upload" with file://
</name> </name>
<command> <command option="no-include">
file://localhost/%PWD/log/nonexisting/result205.txt -T log/upload205.txt file://localhost/%PWD/log/nonexisting/result205.txt -T log/upload205.txt
</command> </command>
<file name="log/upload205.txt"> <file name="log/upload205.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
basic file:// file with no authority basic file:// file with no authority
</name> </name>
<command> <command option="no-include">
file:%PWD/log/test2070.txt file:%PWD/log/test2070.txt
</command> </command>
<file name="log/test2070.txt"> <file name="log/test2070.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
basic file:// file with "127.0.0.1" hostname basic file:// file with "127.0.0.1" hostname
</name> </name>
<command> <command option="no-include">
file://127.0.0.1/%PWD/log/test2070.txt file://127.0.0.1/%PWD/log/test2070.txt
</command> </command>
<file name="log/test2070.txt"> <file name="log/test2070.txt">

View file

@ -23,7 +23,7 @@ file
<name> <name>
file:// with unix path resolution behavior for the case of extra slashes file:// with unix path resolution behavior for the case of extra slashes
</name> </name>
<command> <command option="no-include">
file:////%PWD/log/test2072.txt file:////%PWD/log/test2072.txt
</command> </command>
<precheck> <precheck>

View file

@ -22,7 +22,7 @@ ftp
<name> <name>
Get two FTP files from the same remote dir: no second CWD Get two FTP files from the same remote dir: no second CWD
</name> </name>
<command> <command option="no-include">
ftp://%HOSTIP:%FTPPORT/a/path/210 ftp://%HOSTIP:%FTPPORT/a/path/210 ftp://%HOSTIP:%FTPPORT/a/path/210 ftp://%HOSTIP:%FTPPORT/a/path/210
</command> </command>
<stdout> <stdout>

View file

@ -22,7 +22,7 @@ file
<name> <name>
file:// with resume file:// with resume
</name> </name>
<command> <command option="no-include">
file://localhost/%PWD/log/test231.txt -C 10 file://localhost/%PWD/log/test231.txt -C 10
</command> </command>
<file name="log/test231.txt"> <file name="log/test231.txt">

View file

@ -30,7 +30,7 @@ file:// with (unsupported) proxy, authentication and range
<setenv> <setenv>
all_proxy=http://fake:user@%HOSTIP:%HTTPPORT/ all_proxy=http://fake:user@%HOSTIP:%HTTPPORT/
</setenv> </setenv>
<command> <command option="no-include">
file://localhost/%PWD/log/test288.txt file://localhost/%PWD/log/test288.txt
</command> </command>
<file name="log/test288.txt"> <file name="log/test288.txt">