1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

curl --head now reports info "headers" on file:// URLs as well

This commit is contained in:
Daniel Stenberg 2003-10-30 09:08:16 +00:00
parent 5554f1ccba
commit fb26b2bd98
3 changed files with 50 additions and 8 deletions

View File

@ -7,6 +7,12 @@
Changelog
Daniel (30 October)
- David Hull made libcurl deal with NOBODY and HEADER for file:// the same way
it already does for FTP: it provides HTTP-looking headers that provide info
only about the file, without doing the actual transfer. The curl tool then
lets --head do this.
Daniel (29 October)
- runtests.pl now checks for and use valgrind if present. It will redirect the
valgrind results in log/valgrind[num] but it currently doesn't scan that

View File

@ -367,10 +367,11 @@ name, IP address or host name. An example could look like:
If this option is used several times, the last one will be used.
.IP "-I/--head"
(HTTP/FTP)
(HTTP/FTP/FILE)
Fetch the HTTP-header only! HTTP-servers feature the command HEAD
which this uses to get nothing but the header of a document. When used
on a FTP file, curl displays the file size only.
on a FTP or FILE file, curl displays the file size and last modification
time only.
If this option is used twice, the second will again disable header only.
.IP "-j/--junk-session-cookies"

View File

@ -163,7 +163,8 @@ CURLcode Curl_file(struct connectdata *conn)
*/
CURLcode res = CURLE_OK;
struct stat statbuf;
double expected_size=-1;
unsigned long expected_size=0;
bool fstated=FALSE;
ssize_t nread;
struct SessionHandle *data = conn->data;
char *buf = data->state.buffer;
@ -178,25 +179,59 @@ CURLcode Curl_file(struct connectdata *conn)
/*VMS?? -- This only works reliable for STREAMLF files */
if( -1 != fstat(fd, &statbuf)) {
/* we could stat it, then read out the size */
expected_size = (double)statbuf.st_size;
expected_size = statbuf.st_size;
fstated = TRUE;
}
/* 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.no_body && data->set.include_header && fstated) {
CURLcode result;
sprintf(buf, "Content-Length: %lu\r\n", expected_size);
result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
if(result)
return result;
sprintf(buf, "Accept-ranges: bytes\r\n");
result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
if(result)
return result;
#ifdef HAVE_STRFTIME
if(fstated) {
struct tm *tm;
#ifdef HAVE_LOCALTIME_R
struct tm buffer;
tm = (struct tm *)localtime_r((time_t *)&statbuf.st_mtime, &buffer);
#else
tm = localtime((time_t *)&statbuf.st_mtime);
#endif
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n",
tm);
result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
}
#endif
return result;
}
/* Added by Dolbneff A.V & Spiridonoff A.V */
if (conn->resume_from <= expected_size)
if (conn->resume_from <= (long)expected_size)
expected_size -= conn->resume_from;
else
/* Is this error code suitable in such situation? */
return CURLE_FTP_BAD_DOWNLOAD_RESUME;
if (expected_size == 0)
if (fstated && (expected_size == 0))
return CURLE_OK;
/* The following is a shortcut implementation of file reading
this is both more efficient than the former call to download() and
it avoids problems with select() and recv() on file descriptors
in Winsock */
if(expected_size != -1)
Curl_pgrsSetDownloadSize(data, expected_size);
if(fstated)
Curl_pgrsSetDownloadSize(data, (double)expected_size);
if(conn->resume_from)
/* Added by Dolbneff A.V & Spiridonoff A.V */