/* HTTP support.
- Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001
+ Free Software Foundation, Inc.
-This file is part of Wget.
+This file is part of GNU Wget.
-This program is free software; you can redistribute it and/or modify
+GNU Wget is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-This program is distributed in the hope that it will be useful,
+GNU Wget is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+along with Wget; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
keep_alive = 0;
http_keep_alive_1 = http_keep_alive_2 = 0;
- if (opt.cookies)
- cookies = build_cookies_request (u->host, u->port, u->path,
- u->proto == URLHTTPS);
-
/* Initialize certain elements of struct http_stat. */
hs->len = 0L;
hs->contlen = -1;
else
request_keep_alive = NULL;
+ if (opt.cookies)
+ cookies = build_cookies_request (ou->host, ou->port, ou->path,
+ ou->proto == URLHTTPS);
+
/* Allocate the memory for the request. */
request = (char *)alloca (strlen (command) + strlen (path)
+ strlen (useragent)
if (opt.always_rest)
{
/* Check for condition #2. */
- if (hs->restval >= contlen)
+ if (hs->restval > 0 /* restart was requested. */
+ && contlen != -1 /* we got content-length. */
+ && hs->restval >= contlen /* file fully downloaded
+ or has shrunk. */
+ )
{
logputs (LOG_VERBOSE, _("\
\n The file is already fully retrieved; nothing to do.\n\n"));
logprintf (LOG_NOTQUIET,
_("\
\n\
-The server does not support continued downloads, which conflicts with `-c'.\n\
-Refusing to truncate `%s'.\n\n"), u->local);
+Continued download failed on this file, which conflicts with `-c'.\n\
+Refusing to truncate existing file `%s'.\n\n"), u->local);
FREE_MAYBE (type);
FREE_MAYBE (all_headers);
CLOSE_INVALIDATE (sock);
hstat.restval = 0L;
/* Decide whether or not to restart. */
if (((count > 1 && (*dt & ACCEPTRANGES)) || opt.always_rest)
+ /* #### this calls access() and then stat(); could be optimized. */
&& file_exists_p (locf))
if (stat (locf, &st) == 0 && S_ISREG (st.st_mode))
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. */
+ hstat.no_truncate = 0;
if (opt.always_rest && hstat.restval)
- hstat.no_truncate = file_exists_p (locf);
+ hstat.no_truncate = 1;
/* Decide whether to send the no-cache directive. We send it in
two cases: