]> sjero.net Git - wget/commitdiff
Support HTTP/1.1 307 redirects keep request method.
authorFilipe Brandenburger <filbranden@gmail.com>
Thu, 3 Mar 2011 13:02:25 +0000 (14:02 +0100)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Thu, 3 Mar 2011 13:02:25 +0000 (14:02 +0100)
NEWS
src/ChangeLog
src/http.c
src/retr.c
src/wget.h

diff --git a/NEWS b/NEWS
index ff2ed06d47d55e1c6f5a1ccbde9fa2028dd6a21a..5a3cc2fa29a1e41512eb6692f2b6e9ff30844802 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,8 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
 
 ** Now --adjust-extension does not modify the file extension if the file ends
    in .htm.
 
 ** Now --adjust-extension does not modify the file extension if the file ends
    in .htm.
+
+** Support HTTP/1.1 307 redirects keep request method.
 \f
 * Changes in Wget 1.12
 
 \f
 * Changes in Wget 1.12
 
index 6230268609b2f650722e1901cd9fa59e5fdd5d10..28aa1a5912ad7bbc082a9c5882df9f08244f0c96 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-20  Filipe Brandenburger <filbranden@gmail.com> (tiny change)
+
+       * http.c (gethttp): Repeat a POST request on a 307 response.
+       * retr.c (retrieve_url): Use NEWLOCATION_KEEP_POST.
+       * wget.h: Define NEWLOCATION_KEEP_POST.
+
 2011-03-02  Tomasz Buchert <tomek.buchert@gmail.com> (tiny change)
 
        * http.c (ensure_extension): Do not adjust the extension if the file
 2011-03-02  Tomasz Buchert <tomek.buchert@gmail.com> (tiny change)
 
        * http.c (ensure_extension): Do not adjust the extension if the file
index d7e55ca824318747f447d6fa4d2be5748c87db78..1aa9ef02b626ed61250e040be3748e05456511f2 100644 (file)
@@ -2323,6 +2323,15 @@ read_header:
             CLOSE_INVALIDATE (sock);
           xfree_null (type);
           xfree (head);
             CLOSE_INVALIDATE (sock);
           xfree_null (type);
           xfree (head);
+          /* From RFC2616: The status codes 303 and 307 have
+             been added for servers that wish to make unambiguously
+             clear which kind of reaction is expected of the client.
+             
+             A 307 should be redirected using the same method,
+             in other words, a POST should be preserved and not
+             converted to a GET in that case. */
+          if (statcode == HTTP_STATUS_TEMPORARY_REDIRECT)
+            return NEWLOCATION_KEEP_POST;
           return NEWLOCATION;
         }
     }
           return NEWLOCATION;
         }
     }
@@ -2790,6 +2799,7 @@ Spider mode enabled. Check if remote file exists.\n"));
           ret = err;
           goto exit;
         case NEWLOCATION:
           ret = err;
           goto exit;
         case NEWLOCATION:
+        case NEWLOCATION_KEEP_POST:
           /* Return the new location to the caller.  */
           if (!*newloc)
             {
           /* Return the new location to the caller.  */
           if (!*newloc)
             {
@@ -2800,7 +2810,7 @@ Spider mode enabled. Check if remote file exists.\n"));
             }
           else
             {
             }
           else
             {
-              ret = NEWLOCATION;
+              ret = err;
             }
           goto exit;
         case RETRUNNEEDED:
             }
           goto exit;
         case RETRUNNEEDED:
index 1c587a2cb4bc0dd372915df3ad6a13ac696b03de..25c5dcf4440e11da851db0e3101d48ead723aa8b 100644 (file)
@@ -764,7 +764,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
       proxy_url = NULL;
     }
 
       proxy_url = NULL;
     }
 
-  location_changed = (result == NEWLOCATION);
+  location_changed = (result == NEWLOCATION || result == NEWLOCATION_KEEP_POST);
   if (location_changed)
     {
       char *construced_newloc;
   if (location_changed)
     {
       char *construced_newloc;
@@ -838,12 +838,17 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
         }
       u = newloc_parsed;
 
         }
       u = newloc_parsed;
 
-      /* If we're being redirected from POST, we don't want to POST
+      /* If we're being redirected from POST, and we received a
+         redirect code different than 307, we don't want to POST
          again.  Many requests answer POST with a redirection to an
          index page; that redirection is clearly a GET.  We "suspend"
          POST data for the duration of the redirections, and restore
          again.  Many requests answer POST with a redirection to an
          index page; that redirection is clearly a GET.  We "suspend"
          POST data for the duration of the redirections, and restore
-         it when we're done. */
-      if (!post_data_suspended)
+         it when we're done.
+        
+        RFC2616 HTTP/1.1 introduces code 307 Temporary Redirect
+        specifically to preserve the method of the request.
+        */
+      if (result != NEWLOCATION_KEEP_POST && !post_data_suspended)
         SUSPEND_POST_DATA;
 
       goto redirected;
         SUSPEND_POST_DATA;
 
       goto redirected;
index 16269bf387d94286f98589cb3cf6b8a44ee5d594..fce89e7a9f92eab8df55c9a7a65b001d26fc05ff 100644 (file)
@@ -353,7 +353,7 @@ typedef enum
   PROXERR,
   /* 50  */
   AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, VERIFCERTERR,
   PROXERR,
   /* 50  */
   AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, VERIFCERTERR,
-  UNLINKERR
+  UNLINKERR, NEWLOCATION_KEEP_POST
 } uerr_t;
 
 /* 2005-02-19 SMS.
 } uerr_t;
 
 /* 2005-02-19 SMS.