mirror of
https://github.com/curl/curl.git
synced 2026-06-22 05:16:15 +03:00
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:
parent
b55e85d4ec
commit
e50a2002bd
33 changed files with 82 additions and 86 deletions
27
lib/file.c
27
lib/file.c
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
|
|||
#ifdef USE_SSL
|
||||
Curl_ssl_free_certinfo(data);
|
||||
#endif
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue