]> sjero.net Git - wget/blobdiff - src/http.c
[svn] Fixes by Christian Biere:
[wget] / src / http.c
index a305cbe9a6c386030448d05d5d86b0b5e048909c..b779e36ee6f71d82318c8e5ba7e9780bcbbbf5c5 100644 (file)
@@ -92,8 +92,9 @@ struct cookie_jar *wget_cookie_jar;
 /* Some status code validation macros: */
 #define H_20X(x)        (((x) >= 200) && ((x) < 300))
 #define H_PARTIAL(x)    ((x) == HTTP_STATUS_PARTIAL_CONTENTS)
-#define H_REDIRECTED(x) ((x) == HTTP_STATUS_MOVED_PERMANENTLY  \
-                         || (x) == HTTP_STATUS_MOVED_TEMPORARILY \
+#define H_REDIRECTED(x) ((x) == HTTP_STATUS_MOVED_PERMANENTLY          \
+                         || (x) == HTTP_STATUS_MOVED_TEMPORARILY       \
+                        || (x) == HTTP_STATUS_SEE_OTHER                \
                         || (x) == HTTP_STATUS_TEMPORARY_REDIRECT)
 
 /* HTTP/1.0 status codes from RFC1945, provided for reference.  */
@@ -108,8 +109,9 @@ struct cookie_jar *wget_cookie_jar;
 #define HTTP_STATUS_MULTIPLE_CHOICES   300
 #define HTTP_STATUS_MOVED_PERMANENTLY  301
 #define HTTP_STATUS_MOVED_TEMPORARILY  302
+#define HTTP_STATUS_SEE_OTHER           303 /* from HTTP/1.1 */
 #define HTTP_STATUS_NOT_MODIFIED       304
-#define HTTP_STATUS_TEMPORARY_REDIRECT  307
+#define HTTP_STATUS_TEMPORARY_REDIRECT  307 /* from HTTP/1.1 */
 
 /* Client error 4xx.  */
 #define HTTP_STATUS_BAD_REQUEST                400
@@ -579,8 +581,8 @@ response_header_copy (const struct response *resp, const char *name,
     return 0;
   if (bufsize)
     {
-      int len = MIN (e - b, bufsize);
-      strncpy (buf, b, len);
+      int len = MIN (e - b, bufsize - 1);
+      memcpy (buf, b, len);
       buf[len] = '\0';
     }
   return 1;
@@ -980,7 +982,8 @@ struct http_stat
   char *remote_time;           /* remote time-stamp string */
   char *error;                 /* textual HTTP error */
   int statcode;                        /* status code */
-  double dltime;               /* time of the download in msecs */
+  long rd_size;                        /* amount of data read from socket */
+  double dltime;               /* time it took to download the data */
   const char *referer;         /* value of the referer header. */
   char **local_file;           /* local file. */
 };
@@ -1250,8 +1253,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
            }
        }
       request_set_header (req, "Content-Length",
-                         aprintf ("Content-Length: %ld", post_data_size),
-                         rel_value);
+                         aprintf ("%ld", post_data_size), rel_value);
     }
 
   /* Add the user headers. */
@@ -1715,10 +1717,14 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   if (keep_alive)
     flags |= rb_read_exactly;
   if (hs->restval > 0 && contrange == 0)
+    /* If the server ignored our range request, instruct fd_read_body
+       to skip the first RESTVAL bytes of body.  */
     flags |= rb_skip_startpos;
+  hs->len = hs->restval;
+  hs->rd_size = 0;
   hs->res = fd_read_body (sock, fp, contlen != -1 ? contlen : 0,
-                         hs->restval, &hs->len, &hs->dltime, flags);
-  hs->len += hs->restval;
+                         hs->restval, &hs->rd_size, &hs->len, &hs->dltime,
+                         flags);
 
   if (hs->res >= 0)
     CLOSE_FINISH (sock);
@@ -1898,7 +1904,7 @@ File `%s' already there, will not retrieve.\n"), *hstat.local_file);
       if (opt.verbose)
        {
          char *hurl = url_string (u, 1);
-         char tmp[15];
+         char tmp[256];
          strcpy (tmp, "        ");
          if (count > 1)
            sprintf (tmp, _("(try:%2d)"), count);
@@ -2120,7 +2126,7 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
          return RETROK;
        }
 
-      tmrate = retr_rate (hstat.len - hstat.restval, hstat.dltime, 0);
+      tmrate = retr_rate (hstat.rd_size, hstat.dltime, 0);
 
       if (hstat.len == hstat.contlen)
        {