diff options
author | cracauer <cracauer@FreeBSD.org> | 1998-12-08 13:00:49 +0000 |
---|---|---|
committer | cracauer <cracauer@FreeBSD.org> | 1998-12-08 13:00:49 +0000 |
commit | c4f0cd91dfd075657106a1cf7a6b6e0b3a1712f9 (patch) | |
tree | fc3f9e64c7788a6155478c488fe7065670d41463 /usr.bin/fetch/http.c | |
parent | b34285d7af1280b5524d2efb346146f3bb7834e1 (diff) | |
download | FreeBSD-src-c4f0cd91dfd075657106a1cf7a6b6e0b3a1712f9.zip FreeBSD-src-c4f0cd91dfd075657106a1cf7a6b6e0b3a1712f9.tar.gz |
Add -s option, just report size of file that would be fetched.
Reviewed by: -current list
Diffstat (limited to 'usr.bin/fetch/http.c')
-rw-r--r-- | usr.bin/fetch/http.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/usr.bin/fetch/http.c b/usr.bin/fetch/http.c index 24b63eb..ff8d25f 100644 --- a/usr.bin/fetch/http.c +++ b/usr.bin/fetch/http.c @@ -26,7 +26,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: http.c,v 1.20 1998/09/20 00:01:26 jkh Exp $ + * $Id: http.c,v 1.21 1998/10/26 02:39:21 fenner Exp $ */ #include <sys/types.h> @@ -440,6 +440,7 @@ http_retrieve(struct fetch_state *fs) char *base64ofmd5; int to_stdout, restarting, redirection, retrying, autherror, chunked; char rangebuf[sizeof("Range: bytes=18446744073709551616-\r\n")]; + int tried_head; setup_http_auth(); @@ -448,6 +449,7 @@ http_retrieve(struct fetch_state *fs) restarting = fs->fs_restart; redirection = 0; retrying = 0; + tried_head = 0; /* * Figure out the timeout. Prefer the -T command-line value, @@ -507,7 +509,14 @@ http_retrieve(struct fetch_state *fs) } while(0) retry: - addstr(iov, n, "GET "); + if (fs->fs_reportsize && !tried_head) { + addstr(iov, n, "HEAD "); + tried_head = 1; + } + else { + addstr(iov, n, "GET "); + tried_head = 0; + } addstr(iov, n, https->http_remote_request); addstr(iov, n, " HTTP/1.1\r\n"); /* @@ -738,6 +747,16 @@ got100reply: else autherror = 407; break; + case 501: /* Not Implemented */ + /* If we tried HEAD, retry with GET */ + if (tried_head) { + n = 0; + goto retry; + } + else { + errstr = safe_strdup(line); + break; + } case 503: /* Service Unavailable */ if (!fs->fs_auto_retry) errstr = safe_strdup(line); @@ -945,6 +964,23 @@ spewerror: fs->fs_status = "retrieving file from HTTP/1.x server"; + if (fs->fs_reportsize) { + if (total_length == -1) { + warnx("%s: size not known\n", + fs->fs_outputfile); + printf("Unknown\n"); + status = 1; + } + else { + printf("%qd\n", (quad_t)total_length); + status = 0; + } + fclose(remote); + unsetup_sigalrm(); + return status; + } + + /* * OK, if we got here, then we have finished parsing the header * and have read the `\r\n' line which denotes the end of same. |