]> sjero.net Git - wget/commitdiff
[svn] Commit various HTTP fixes.
authorhniksic <devnull@localhost>
Sat, 28 Apr 2001 16:22:20 +0000 (09:22 -0700)
committerhniksic <devnull@localhost>
Sat, 28 Apr 2001 16:22:20 +0000 (09:22 -0700)
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".

src/ChangeLog
src/http.c
src/main.c
src/wget.h

index 19e9cb2f94681e3d6590ba96d5f30da5c6d08fc8..21f675a3ca9cd1420dc4952cb77459da32f2157a 100644 (file)
@@ -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>
 
        * http.c (http_loop): If allow_cache is zero, always disable
index ecf29384c68708116e3a28422c97975775cf7993..9f6cb4953fa3d1f7db1dc468b9c50bfbffc50454 100644 (file)
@@ -909,7 +909,6 @@ Accept: %s\r\n\
          logputs (LOG_NOTQUIET, _("End of file while parsing headers.\n"));
          xfree (hdr);
          FREE_MAYBE (type);
-         FREE_MAYBE (hs->newloc);
          FREE_MAYBE (all_headers);
          CLOSE_INVALIDATE (sock);
          return HEOF;
@@ -921,7 +920,6 @@ Accept: %s\r\n\
                     strerror (errno));
          xfree (hdr);
          FREE_MAYBE (type);
-         FREE_MAYBE (hs->newloc);
          FREE_MAYBE (all_headers);
          CLOSE_INVALIDATE (sock);
          return HERR;
@@ -1121,6 +1119,30 @@ Accept: %s\r\n\
   if (H_20X (statcode))
     *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)))
     *dt |= TEXTHTML;
   else
@@ -1168,7 +1190,7 @@ Accept: %s\r\n\
       if (opt.always_rest)
        {
          /* Check for condition #2. */
-         if (hs->restval == contlen)
+         if (hs->restval >= contlen)
            {
              logputs (LOG_VERBOSE, _("\
 \n    The file is already fully retrieved; nothing to do.\n\n"));
@@ -1176,11 +1198,10 @@ Accept: %s\r\n\
              hs->len = contlen;
              hs->res = 0;
              FREE_MAYBE (type);
-             FREE_MAYBE (hs->newloc);
              FREE_MAYBE (all_headers);
              CLOSE_INVALIDATE (sock);  /* would be CLOSE_FINISH, but there
                                           might be more bytes in the body. */
-             return RETRFINISHED;
+             return RETRUNNEEDED;
            }
 
          /* Check for condition #1. */
@@ -1189,8 +1210,11 @@ Accept: %s\r\n\
              logprintf (LOG_NOTQUIET,
                         _("\
 \n\
-    The server does not support continued download;\n\
-    refusing to truncate `%s'.\n\n"), u->local);
+The server does not support continued downloads, which conflicts with `-c'.\n\
+Refusing to truncate `%s'.\n\n"), u->local);
+             FREE_MAYBE (type);
+             FREE_MAYBE (all_headers);
+             CLOSE_INVALIDATE (sock);
              return CONTNOTSUPPORTED;
            }
 
@@ -1199,14 +1223,12 @@ Accept: %s\r\n\
 
       hs->restval = 0;
     }
-
   else if (contrange != hs->restval ||
           (H_PARTIAL (statcode) && contrange == -1))
     {
       /* This means the whole request was somehow misunderstood by the
         server.  Bail out.  */
       FREE_MAYBE (type);
-      FREE_MAYBE (hs->newloc);
       FREE_MAYBE (all_headers);
       CLOSE_INVALIDATE (sock);
       return RANGEERR;
@@ -1222,29 +1244,6 @@ Accept: %s\r\n\
     }
   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 ((*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))
          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
         two cases:
           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
        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?  */
       tms = time_str (NULL);
       /* 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! */
          return NEWLOCATION;
          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:
          /* Deal with you later.  */
          break;
index de94a60c61fc417e4e2903421996f958e224e382..5f1f26035391e67261aae4cf30fae159465aeab1 100644 (file)
@@ -192,7 +192,7 @@ HTTP options:\n\
        --referer=URL         include `Referer: URL\' header in HTTP request.\n\
   -s,  --save-headers        save the HTTP headers to file.\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\
        --save-cookies=FILE   save cookies to FILE after session.\n\
 \n"), stdout);
index 0fa9765f59d15968f2755182b8533bb6b8f44924..05d054c1cbe8f890887668c3ca57ead32abf4715 100644 (file)
@@ -290,7 +290,7 @@ typedef enum
   URLBADHOST, FOPENERR, FWRITEERR, HOK, HLEXC, HEOF,
   HERR, RETROK, RECLEVELEXC, FTPACCDENIED, WRONGCODE,
   FTPINVPASV, FTPNOPASV,
-  CONTNOTSUPPORTED, RETRFINISHED, READERR, TRYLIMEXC,
+  CONTNOTSUPPORTED, RETRUNNEEDED, RETRFINISHED, READERR, TRYLIMEXC,
   URLBADPATTERN, FILEBADFILE, RANGEERR, RETRBADPATTERN,
   RETNOTSUP, ROBOTSOK, NOROBOTS, PROXERR, AUTHFAILED,
   QUOTEXC, WRITEFAILED,