mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Commit various HTTP fixes.
Published in <sxsy9slhu7g.fsf@florida.arsdigita.de>. * http.c (gethttp): Return RETRUNNEEDED when the retrieval is unneeded because the file is already there and fully downloaded, and -c is specified. (http_loop): Handle RETRUNNEEDED. * wget.h (uerr_t): New value RETRUNNEEDED. * http.c (http_loop): Set no_truncate for files that both exist and are non-empty. (gethttp): Consider the download finished when restval >= contlen, not only when restval==contlen. (gethttp): Handle redirection before giving up due to -c. (gethttp): Clarify error message which explains that -c will not truncate the file. (gethttp): When returning CONTNOTSUPPORTED, don't forget to free the stuff that needs freeing and release the socket. * main.c (print_help): Wget booleans accept "off", not "no".
This commit is contained in:
parent
7b3c3a4cb8
commit
d70101ea4e
@ -1,3 +1,26 @@
|
|||||||
|
2001-04-28 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
|
* http.c (gethttp): Return RETRUNNEEDED when the retrieval is
|
||||||
|
unneeded because the file is already there and fully downloaded,
|
||||||
|
and -c is specified.
|
||||||
|
(http_loop): Handle RETRUNNEEDED.
|
||||||
|
|
||||||
|
* wget.h (uerr_t): New value RETRUNNEEDED.
|
||||||
|
|
||||||
|
* http.c (http_loop): Set no_truncate for files that both exist
|
||||||
|
and are non-empty.
|
||||||
|
(gethttp): Consider the download finished when restval >= contlen,
|
||||||
|
not only when restval==contlen.
|
||||||
|
(gethttp): Handle redirection before giving up due to -c.
|
||||||
|
(gethttp): Clarify error message which explains that -c will not
|
||||||
|
truncate the file.
|
||||||
|
(gethttp): When returning CONTNOTSUPPORTED, don't forget to free
|
||||||
|
the stuff that needs freeing and release the socket.
|
||||||
|
|
||||||
|
2001-04-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
|
* main.c (print_help): Wget booleans accept "off", not "no".
|
||||||
|
|
||||||
2001-04-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
2001-04-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
* http.c (http_loop): If allow_cache is zero, always disable
|
* http.c (http_loop): If allow_cache is zero, always disable
|
||||||
|
82
src/http.c
82
src/http.c
@ -909,7 +909,6 @@ Accept: %s\r\n\
|
|||||||
logputs (LOG_NOTQUIET, _("End of file while parsing headers.\n"));
|
logputs (LOG_NOTQUIET, _("End of file while parsing headers.\n"));
|
||||||
xfree (hdr);
|
xfree (hdr);
|
||||||
FREE_MAYBE (type);
|
FREE_MAYBE (type);
|
||||||
FREE_MAYBE (hs->newloc);
|
|
||||||
FREE_MAYBE (all_headers);
|
FREE_MAYBE (all_headers);
|
||||||
CLOSE_INVALIDATE (sock);
|
CLOSE_INVALIDATE (sock);
|
||||||
return HEOF;
|
return HEOF;
|
||||||
@ -921,7 +920,6 @@ Accept: %s\r\n\
|
|||||||
strerror (errno));
|
strerror (errno));
|
||||||
xfree (hdr);
|
xfree (hdr);
|
||||||
FREE_MAYBE (type);
|
FREE_MAYBE (type);
|
||||||
FREE_MAYBE (hs->newloc);
|
|
||||||
FREE_MAYBE (all_headers);
|
FREE_MAYBE (all_headers);
|
||||||
CLOSE_INVALIDATE (sock);
|
CLOSE_INVALIDATE (sock);
|
||||||
return HERR;
|
return HERR;
|
||||||
@ -1121,6 +1119,30 @@ Accept: %s\r\n\
|
|||||||
if (H_20X (statcode))
|
if (H_20X (statcode))
|
||||||
*dt |= RETROKF;
|
*dt |= RETROKF;
|
||||||
|
|
||||||
|
/* Return if redirected. */
|
||||||
|
if (H_REDIRECTED (statcode) || statcode == HTTP_STATUS_MULTIPLE_CHOICES)
|
||||||
|
{
|
||||||
|
/* RFC2068 says that in case of the 300 (multiple choices)
|
||||||
|
response, the server can output a preferred URL through
|
||||||
|
`Location' header; otherwise, the request should be treated
|
||||||
|
like GET. So, if the location is set, it will be a
|
||||||
|
redirection; otherwise, just proceed normally. */
|
||||||
|
if (statcode == HTTP_STATUS_MULTIPLE_CHOICES && !hs->newloc)
|
||||||
|
*dt |= RETROKF;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logprintf (LOG_VERBOSE,
|
||||||
|
_("Location: %s%s\n"),
|
||||||
|
hs->newloc ? hs->newloc : _("unspecified"),
|
||||||
|
hs->newloc ? _(" [following]") : "");
|
||||||
|
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
|
||||||
|
might be more bytes in the body. */
|
||||||
|
FREE_MAYBE (type);
|
||||||
|
FREE_MAYBE (all_headers);
|
||||||
|
return NEWLOCATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (type && !strncasecmp (type, TEXTHTML_S, strlen (TEXTHTML_S)))
|
if (type && !strncasecmp (type, TEXTHTML_S, strlen (TEXTHTML_S)))
|
||||||
*dt |= TEXTHTML;
|
*dt |= TEXTHTML;
|
||||||
else
|
else
|
||||||
@ -1168,7 +1190,7 @@ Accept: %s\r\n\
|
|||||||
if (opt.always_rest)
|
if (opt.always_rest)
|
||||||
{
|
{
|
||||||
/* Check for condition #2. */
|
/* Check for condition #2. */
|
||||||
if (hs->restval == contlen)
|
if (hs->restval >= contlen)
|
||||||
{
|
{
|
||||||
logputs (LOG_VERBOSE, _("\
|
logputs (LOG_VERBOSE, _("\
|
||||||
\n The file is already fully retrieved; nothing to do.\n\n"));
|
\n The file is already fully retrieved; nothing to do.\n\n"));
|
||||||
@ -1176,11 +1198,10 @@ Accept: %s\r\n\
|
|||||||
hs->len = contlen;
|
hs->len = contlen;
|
||||||
hs->res = 0;
|
hs->res = 0;
|
||||||
FREE_MAYBE (type);
|
FREE_MAYBE (type);
|
||||||
FREE_MAYBE (hs->newloc);
|
|
||||||
FREE_MAYBE (all_headers);
|
FREE_MAYBE (all_headers);
|
||||||
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
|
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
|
||||||
might be more bytes in the body. */
|
might be more bytes in the body. */
|
||||||
return RETRFINISHED;
|
return RETRUNNEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for condition #1. */
|
/* Check for condition #1. */
|
||||||
@ -1189,8 +1210,11 @@ Accept: %s\r\n\
|
|||||||
logprintf (LOG_NOTQUIET,
|
logprintf (LOG_NOTQUIET,
|
||||||
_("\
|
_("\
|
||||||
\n\
|
\n\
|
||||||
The server does not support continued download;\n\
|
The server does not support continued downloads, which conflicts with `-c'.\n\
|
||||||
refusing to truncate `%s'.\n\n"), u->local);
|
Refusing to truncate `%s'.\n\n"), u->local);
|
||||||
|
FREE_MAYBE (type);
|
||||||
|
FREE_MAYBE (all_headers);
|
||||||
|
CLOSE_INVALIDATE (sock);
|
||||||
return CONTNOTSUPPORTED;
|
return CONTNOTSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1199,14 +1223,12 @@ Accept: %s\r\n\
|
|||||||
|
|
||||||
hs->restval = 0;
|
hs->restval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (contrange != hs->restval ||
|
else if (contrange != hs->restval ||
|
||||||
(H_PARTIAL (statcode) && contrange == -1))
|
(H_PARTIAL (statcode) && contrange == -1))
|
||||||
{
|
{
|
||||||
/* This means the whole request was somehow misunderstood by the
|
/* This means the whole request was somehow misunderstood by the
|
||||||
server. Bail out. */
|
server. Bail out. */
|
||||||
FREE_MAYBE (type);
|
FREE_MAYBE (type);
|
||||||
FREE_MAYBE (hs->newloc);
|
|
||||||
FREE_MAYBE (all_headers);
|
FREE_MAYBE (all_headers);
|
||||||
CLOSE_INVALIDATE (sock);
|
CLOSE_INVALIDATE (sock);
|
||||||
return RANGEERR;
|
return RANGEERR;
|
||||||
@ -1222,29 +1244,6 @@ Accept: %s\r\n\
|
|||||||
}
|
}
|
||||||
hs->contlen = contlen;
|
hs->contlen = contlen;
|
||||||
|
|
||||||
/* Return if redirected. */
|
|
||||||
if (H_REDIRECTED (statcode) || statcode == HTTP_STATUS_MULTIPLE_CHOICES)
|
|
||||||
{
|
|
||||||
/* RFC2068 says that in case of the 300 (multiple choices)
|
|
||||||
response, the server can output a preferred URL through
|
|
||||||
`Location' header; otherwise, the request should be treated
|
|
||||||
like GET. So, if the location is set, it will be a
|
|
||||||
redirection; otherwise, just proceed normally. */
|
|
||||||
if (statcode == HTTP_STATUS_MULTIPLE_CHOICES && !hs->newloc)
|
|
||||||
*dt |= RETROKF;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logprintf (LOG_VERBOSE,
|
|
||||||
_("Location: %s%s\n"),
|
|
||||||
hs->newloc ? hs->newloc : _("unspecified"),
|
|
||||||
hs->newloc ? _(" [following]") : "");
|
|
||||||
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
|
|
||||||
might be more bytes in the body. */
|
|
||||||
FREE_MAYBE (type);
|
|
||||||
FREE_MAYBE (all_headers);
|
|
||||||
return NEWLOCATION;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (opt.verbose)
|
if (opt.verbose)
|
||||||
{
|
{
|
||||||
if ((*dt & RETROKF) && !opt.server_response)
|
if ((*dt & RETROKF) && !opt.server_response)
|
||||||
@ -1522,6 +1521,12 @@ File `%s' already there, will not retrieve.\n"), u->local);
|
|||||||
if (stat (locf, &st) == 0 && S_ISREG (st.st_mode))
|
if (stat (locf, &st) == 0 && S_ISREG (st.st_mode))
|
||||||
hstat.restval = st.st_size;
|
hstat.restval = st.st_size;
|
||||||
|
|
||||||
|
/* In `-c' is used and the file is existing and non-empty,
|
||||||
|
refuse to truncate it if the server doesn't support continued
|
||||||
|
downloads. */
|
||||||
|
if (opt.always_rest && hstat.restval)
|
||||||
|
hstat.no_truncate = file_exists_p (locf);
|
||||||
|
|
||||||
/* Decide whether to send the no-cache directive. We send it in
|
/* Decide whether to send the no-cache directive. We send it in
|
||||||
two cases:
|
two cases:
|
||||||
a) we're using a proxy, and we're past our first retrieval.
|
a) we're using a proxy, and we're past our first retrieval.
|
||||||
@ -1547,13 +1552,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
|
|||||||
else
|
else
|
||||||
locf = opt.output_document;
|
locf = opt.output_document;
|
||||||
|
|
||||||
/* In `-c' is used, check whether the file we're writing to
|
|
||||||
exists before we've done anything. If so, we'll refuse to
|
|
||||||
truncate it if the server doesn't support continued
|
|
||||||
downloads. */
|
|
||||||
if (opt.always_rest)
|
|
||||||
hstat.no_truncate = file_exists_p (locf);
|
|
||||||
|
|
||||||
/* Time? */
|
/* Time? */
|
||||||
tms = time_str (NULL);
|
tms = time_str (NULL);
|
||||||
/* Get the new location (with or without the redirection). */
|
/* Get the new location (with or without the redirection). */
|
||||||
@ -1608,6 +1606,12 @@ File `%s' already there, will not retrieve.\n"), u->local);
|
|||||||
xfree (filename_plus_orig_suffix); /* must precede every return! */
|
xfree (filename_plus_orig_suffix); /* must precede every return! */
|
||||||
return NEWLOCATION;
|
return NEWLOCATION;
|
||||||
break;
|
break;
|
||||||
|
case RETRUNNEEDED:
|
||||||
|
/* The file was already fully retrieved. */
|
||||||
|
FREEHSTAT (hstat);
|
||||||
|
xfree (filename_plus_orig_suffix); /* must precede every return! */
|
||||||
|
return RETROK;
|
||||||
|
break;
|
||||||
case RETRFINISHED:
|
case RETRFINISHED:
|
||||||
/* Deal with you later. */
|
/* Deal with you later. */
|
||||||
break;
|
break;
|
||||||
|
@ -192,7 +192,7 @@ HTTP options:\n\
|
|||||||
--referer=URL include `Referer: URL\' header in HTTP request.\n\
|
--referer=URL include `Referer: URL\' header in HTTP request.\n\
|
||||||
-s, --save-headers save the HTTP headers to file.\n\
|
-s, --save-headers save the HTTP headers to file.\n\
|
||||||
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.\n\
|
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.\n\
|
||||||
--cookies=no don't use cookies.\n\
|
--cookies=off don't use cookies.\n\
|
||||||
--load-cookies=FILE load cookies from FILE before session.\n\
|
--load-cookies=FILE load cookies from FILE before session.\n\
|
||||||
--save-cookies=FILE save cookies to FILE after session.\n\
|
--save-cookies=FILE save cookies to FILE after session.\n\
|
||||||
\n"), stdout);
|
\n"), stdout);
|
||||||
|
@ -290,7 +290,7 @@ typedef enum
|
|||||||
URLBADHOST, FOPENERR, FWRITEERR, HOK, HLEXC, HEOF,
|
URLBADHOST, FOPENERR, FWRITEERR, HOK, HLEXC, HEOF,
|
||||||
HERR, RETROK, RECLEVELEXC, FTPACCDENIED, WRONGCODE,
|
HERR, RETROK, RECLEVELEXC, FTPACCDENIED, WRONGCODE,
|
||||||
FTPINVPASV, FTPNOPASV,
|
FTPINVPASV, FTPNOPASV,
|
||||||
CONTNOTSUPPORTED, RETRFINISHED, READERR, TRYLIMEXC,
|
CONTNOTSUPPORTED, RETRUNNEEDED, RETRFINISHED, READERR, TRYLIMEXC,
|
||||||
URLBADPATTERN, FILEBADFILE, RANGEERR, RETRBADPATTERN,
|
URLBADPATTERN, FILEBADFILE, RANGEERR, RETRBADPATTERN,
|
||||||
RETNOTSUP, ROBOTSOK, NOROBOTS, PROXERR, AUTHFAILED,
|
RETNOTSUP, ROBOTSOK, NOROBOTS, PROXERR, AUTHFAILED,
|
||||||
QUOTEXC, WRITEFAILED,
|
QUOTEXC, WRITEFAILED,
|
||||||
|
Loading…
Reference in New Issue
Block a user