Bug 758973 - Make handling of status code 308 more consistent. r=bsmith
authorjulian.reschke@gmx.de
Sat, 22 Sep 2012 11:27:17 -0400
changeset 107921 c4c2b82b79a2344473cc4c066042e109895bc08a
parent 107920 147fc5a585bd6566c341bf27acb71449a1057212
child 107922 b14f17141bb14b10dd8f37efaf242489b3a361dc
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbsmith
bugs758973
milestone18.0a1
Bug 758973 - Make handling of status code 308 more consistent. r=bsmith
netwerk/protocol/http/nsHttp.cpp
netwerk/protocol/http/nsHttp.h
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpResponseHead.cpp
--- a/netwerk/protocol/http/nsHttp.cpp
+++ b/netwerk/protocol/http/nsHttp.cpp
@@ -281,8 +281,15 @@ nsHttp::ParseInt64(const char *input, co
         ++input;
     }
     if (input == start) // nothing parsed?
         return false;
     if (next)
         *next = input;
     return true;
 }
+
+bool
+nsHttp::IsPermanentRedirect(PRUint32 httpStatus)
+{
+  return httpStatus == 301 || httpStatus == 308;
+}
+
--- a/netwerk/protocol/http/nsHttp.h
+++ b/netwerk/protocol/http/nsHttp.h
@@ -175,16 +175,19 @@ struct nsHttp
 
     // Variant on ParseInt64 that expects the input string to contain nothing
     // more than the value being parsed.
     static inline bool ParseInt64(const char *input, int64_t *result) {
         const char *next;
         return ParseInt64(input, &next, result) && *next == '\0';
     }
 
+    // Return whether the HTTP status code represents a permanent redirect
+    static bool IsPermanentRedirect(PRUint32 httpStatus);
+
     // Declare all atoms
     //
     // The atom names and values are stored in nsHttpAtomList.h and are brought
     // to you by the magic of C preprocessing.  Add new atoms to nsHttpAtomList
     // and all support logic will be auto-generated.
     //
 #define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
 #include "nsHttpAtomList.h"
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -4096,17 +4096,17 @@ nsHttpChannel::ContinueProcessRedirectio
     nsCOMPtr<nsIChannel> newChannel;
     rv = ioService->NewChannelFromURI(mRedirectURI, getter_AddRefs(newChannel));
     if (NS_FAILED(rv)) return rv;
 
     rv = SetupReplacementChannel(mRedirectURI, newChannel, !rewriteToGET);
     if (NS_FAILED(rv)) return rv;
 
     uint32_t redirectFlags;
-    if (mRedirectType == 301) // Moved Permanently
+    if (nsHttp::IsPermanentRedirect(mRedirectType))
         redirectFlags = nsIChannelEventSink::REDIRECT_PERMANENT;
     else
         redirectFlags = nsIChannelEventSink::REDIRECT_TEMPORARY;
 
     // verify that this is a legal redirect
     mRedirectChannel = newChannel;
 
     PushRedirectAsyncFunc(&nsHttpChannel::ContinueProcessRedirection);
--- a/netwerk/protocol/http/nsHttpResponseHead.cpp
+++ b/netwerk/protocol/http/nsHttpResponseHead.cpp
@@ -285,17 +285,17 @@ nsHttpResponseHead::ComputeFreshnessLife
         if (date2 <= date) {
             // this only makes sense if last-modified is actually in the past
             *result = (date - date2) / 10;
             return NS_OK;
         }
     }
 
     // These responses can be cached indefinitely.
-    if ((mStatus == 300) || (mStatus == 301)) {
+    if ((mStatus == 300) || nsHttp::IsPermanentRedirect(mStatus)) {
         *result = uint32_t(-1);
         return NS_OK;
     }
 
     LOG(("nsHttpResponseHead::ComputeFreshnessLifetime [this = %x] "
          "Insufficient information to compute a non-zero freshness "
          "lifetime!\n", this));