Bug 1334693 - Add origin attributes to Http2Stream::PushHashKey(). r=mcmanus draft
authorJonathan Hao <jhao@mozilla.com>
Wed, 08 Mar 2017 18:26:08 +0800
changeset 495605 b4c0fe34f7ee08aea63ce58569a84efd0dc57072
parent 495138 166847fdd5c571abcb2b298c1f34c48420f41e21
child 495606 c82319575be5fdd7ecd4d64203700bad7c06f18c
push id48385
push userbmo:jhao@mozilla.com
push dateThu, 09 Mar 2017 03:08:40 +0000
reviewersmcmanus
bugs1334693
milestone54.0a1
Bug 1334693 - Add origin attributes to Http2Stream::PushHashKey(). r=mcmanus MozReview-Commit-ID: He9Ha4SOp2O
netwerk/protocol/http/Http2Push.cpp
netwerk/protocol/http/Http2Stream.cpp
netwerk/protocol/http/Http2Stream.h
--- a/netwerk/protocol/http/Http2Push.cpp
+++ b/netwerk/protocol/http/Http2Push.cpp
@@ -180,22 +180,24 @@ Http2PushedStream::TestOnPush(Http2Strea
 
 nsresult
 Http2PushedStream::ReadSegments(nsAHttpSegmentReader *reader,
                                 uint32_t, uint32_t *count)
 {
   nsresult rv = NS_OK;
   *count = 0;
 
+  mozilla::OriginAttributes originAttributes;
   switch (mUpstreamState) {
   case GENERATING_HEADERS:
     // The request headers for this has been processed, so we need to verify
     // that :authority, :scheme, and :path MUST be present. :method MUST NOT be
     // present
-    CreatePushHashKey(mHeaderScheme, mHeaderHost,
+    mSocketTransport->GetOriginAttributes(&originAttributes);
+    CreatePushHashKey(mHeaderScheme, mHeaderHost, originAttributes,
                       mSession->Serial(), mHeaderPath,
                       mOrigin, mHashKey);
 
     LOG3(("Http2PushStream 0x%X hash key %s\n", mStreamID, mHashKey.get()));
 
     // the write side of a pushed transaction just involves manipulating a little state
     SetSentFin(true);
     Http2Stream::mRequestHeadersDone = 1;
--- a/netwerk/protocol/http/Http2Stream.cpp
+++ b/netwerk/protocol/http/Http2Stream.cpp
@@ -16,16 +16,17 @@
 #include <algorithm>
 
 #include "Http2Compression.h"
 #include "Http2Session.h"
 #include "Http2Stream.h"
 #include "Http2Push.h"
 #include "TunnelUtils.h"
 
+#include "mozilla/BasePrincipal.h"
 #include "mozilla/Telemetry.h"
 #include "nsAlgorithm.h"
 #include "nsHttp.h"
 #include "nsHttpHandler.h"
 #include "nsHttpRequestHead.h"
 #include "nsIClassOfService.h"
 #include "nsIPipe.h"
 #include "nsISocketTransport.h"
@@ -43,18 +44,18 @@ Http2Stream::Http2Stream(nsAHttpTransact
   , mSegmentReader(nullptr)
   , mSegmentWriter(nullptr)
   , mUpstreamState(GENERATING_HEADERS)
   , mState(IDLE)
   , mRequestHeadersDone(0)
   , mOpenGenerated(0)
   , mAllHeadersReceived(0)
   , mQueued(0)
+  , mSocketTransport(session->SocketTransport())
   , mTransaction(httpTransaction)
-  , mSocketTransport(session->SocketTransport())
   , mChunkSize(session->SendingChunkSize())
   , mRequestBlockedOnRead(0)
   , mRecvdFin(0)
   , mReceivedData(0)
   , mRecvdReset(0)
   , mSentReset(0)
   , mCountAsActive(0)
   , mSentFin(0)
@@ -341,16 +342,17 @@ Http2Stream::MakeOriginURL(const nsACStr
                               NS_HTTPS_DEFAULT_PORT,
                           origin, nullptr, nullptr);
   return rv;
 }
 
 void
 Http2Stream::CreatePushHashKey(const nsCString &scheme,
                                const nsCString &hostHeader,
+                               const mozilla::OriginAttributes &originAttributes,
                                uint64_t serial,
                                const nsCSubstring &pathInfo,
                                nsCString &outOrigin,
                                nsCString &outKey)
 {
   nsCString fullOrigin = scheme;
   fullOrigin.AppendLiteral("://");
   fullOrigin.Append(hostHeader);
@@ -364,16 +366,21 @@ Http2Stream::CreatePushHashKey(const nsC
   }
 
   if (NS_FAILED(rv)) {
     // Fallback to plain text copy - this may end up behaving poorly
     outOrigin = fullOrigin;
   }
 
   outKey = outOrigin;
+  outKey.AppendLiteral("/[");
+  nsAutoCString suffix;
+  originAttributes.CreateSuffix(suffix);
+  outKey.Append(suffix);
+  outKey.Append(']');
   outKey.AppendLiteral("/[http2.");
   outKey.AppendInt(serial);
   outKey.Append(']');
   outKey.Append(pathInfo);
 }
 
 nsresult
 Http2Stream::ParseHttpRequestHeaders(const char *buf,
@@ -415,18 +422,21 @@ Http2Stream::ParseHttpRequestHeaders(con
   mRequestHeadersDone = 1;
 
   nsAutoCString authorityHeader;
   nsAutoCString hashkey;
   head->GetHeader(nsHttp::Host, authorityHeader);
 
   nsAutoCString requestURI;
   head->RequestURI(requestURI);
+
+  mozilla::OriginAttributes originAttributes;
+  mSocketTransport->GetOriginAttributes(&originAttributes),
   CreatePushHashKey(nsDependentCString(head->IsHTTPS() ? "https" : "http"),
-                    authorityHeader, mSession->Serial(),
+                    authorityHeader, originAttributes, mSession->Serial(),
                     requestURI,
                     mOrigin, hashkey);
 
   // check the push cache for GET
   if (head->IsGet()) {
     // from :scheme, :authority, :path
     nsIRequestContext *requestContext = mTransaction->RequestContext();
     SpdyPushCache *cache = nullptr;
--- a/netwerk/protocol/http/Http2Stream.h
+++ b/netwerk/protocol/http/Http2Stream.h
@@ -13,16 +13,20 @@
 #include "mozilla/UniquePtr.h"
 #include "nsAHttpTransaction.h"
 #include "nsISupportsPriority.h"
 #include "SimpleBuffer.h"
 
 class nsIInputStream;
 class nsIOutputStream;
 
+namespace mozilla{
+class OriginAttributes;
+}
+
 namespace mozilla {
 namespace net {
 
 class nsStandardURL;
 class Http2Session;
 class Http2Decompressor;
 
 class Http2Stream
@@ -156,16 +160,17 @@ public:
 
   // Mirrors nsAHttpTransaction
   bool Do0RTT();
   nsresult Finish0RTT(bool aRestart, bool aAlpnIgnored);
 
 protected:
   static void CreatePushHashKey(const nsCString &scheme,
                                 const nsCString &hostHeader,
+                                const mozilla::OriginAttributes &originAttributes,
                                 uint64_t serial,
                                 const nsCSubstring &pathInfo,
                                 nsCString &outOrigin,
                                 nsCString &outKey);
 
   // These internal states track request generation
   enum upstreamStateType {
     GENERATING_HEADERS,
@@ -212,16 +217,19 @@ protected:
   // concurrency limits being exceeded
   uint32_t                     mQueued               : 1;
 
   void     ChangeState(enum upstreamStateType);
 
   virtual void AdjustInitialWindow();
   nsresult TransmitFrame(const char *, uint32_t *, bool forceCommitment);
 
+  // The underlying socket transport object is needed to propogate some events
+  nsISocketTransport         *mSocketTransport;
+
 private:
   friend class nsAutoPtr<Http2Stream>;
 
   nsresult ParseHttpRequestHeaders(const char *, uint32_t, uint32_t *);
   nsresult GenerateOpen();
 
   void     AdjustPushedPriority();
   void     GenerateDataFrameHeader(uint32_t, bool);
@@ -229,19 +237,16 @@ private:
   nsresult BufferInput(uint32_t , uint32_t *);
 
   // The underlying HTTP transaction. This pointer is used as the key
   // in the Http2Session mStreamTransactionHash so it is important to
   // keep a reference to it as long as this stream is a member of that hash.
   // (i.e. don't change it or release it after it is set in the ctor).
   RefPtr<nsAHttpTransaction> mTransaction;
 
-  // The underlying socket transport object is needed to propogate some events
-  nsISocketTransport         *mSocketTransport;
-
   // The quanta upstream data frames are chopped into
   uint32_t                    mChunkSize;
 
   // Flag is set when the HTTP processor has more data to send
   // but has blocked in doing so.
   uint32_t                     mRequestBlockedOnRead : 1;
 
   // Flag is set after the response frame bearing the fin bit has