]> sjero.net Git - wget/blobdiff - src/http.c
[svn] Update copyright notices.
[wget] / src / http.c
index f595d29210dd25530ba7d9a0e81024c8699388e2..2ea8a79d452214974d3962036a15ac2a3ad81397 100644 (file)
@@ -1,20 +1,21 @@
 /* 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>
@@ -596,10 +597,6 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
   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;
@@ -807,6 +804,10 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
   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)
@@ -1190,7 +1191,11 @@ Accept: %s\r\n\
       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"));
@@ -1210,8 +1215,8 @@ Accept: %s\r\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);
@@ -1514,6 +1519,7 @@ File `%s' already there, will not retrieve.\n"), u->local);
       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;
@@ -1521,8 +1527,9 @@ File `%s' already there, will not retrieve.\n"), u->local);
       /* 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: