From 426527907a9d43a20949129a0ac81f0d9bccfbe2 Mon Sep 17 00:00:00 2001 From: Junior Hsu Date: Tue, 30 Jun 2020 18:37:28 +0000 Subject: [PATCH] Bug 1578230 - do not process transactions blocked on tunnel before a final response, r=mayhemer,necko-reviewers Depends on D80261 Differential Revision: https://phabricator.services.mozilla.com/D81620 --- netwerk/protocol/http/Http2Stream.cpp | 11 +++++++---- netwerk/protocol/http/Http2Stream.h | 2 +- netwerk/protocol/http/TunnelUtils.cpp | 6 ++++-- netwerk/protocol/http/TunnelUtils.h | 4 +++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/netwerk/protocol/http/Http2Stream.cpp b/netwerk/protocol/http/Http2Stream.cpp index 2850eda2efee..eed2accec5ce 100644 --- a/netwerk/protocol/http/Http2Stream.cpp +++ b/netwerk/protocol/http/Http2Stream.cpp @@ -1053,8 +1053,11 @@ nsresult Http2Stream::ConvertResponseHeaders(Http2Decompressor* decompressor, if ((httpResponseCode / 100) > 2) { MapStreamToPlainText(); } - MapStreamToHttpConnection(aHeadersOut, httpResponseCode); - ClearTransactionsBlockedOnTunnel(); + if (MapStreamToHttpConnection(aHeadersOut, httpResponseCode)) { + // Process transactions only if we have a final response, i.e., response + // code >= 200. + ClearTransactionsBlockedOnTunnel(); + } } else if (mIsWebsocket) { LOG3(("Http2Stream %p websocket response code %d", this, httpResponseCode)); if (httpResponseCode == 200) { @@ -1620,13 +1623,13 @@ void Http2Stream::MapStreamToPlainText() { qiTrans->ForcePlainText(); } -void Http2Stream::MapStreamToHttpConnection(const nsACString& aFlat407Headers, +bool Http2Stream::MapStreamToHttpConnection(const nsACString& aFlat407Headers, int32_t aHttpResponseCode) { RefPtr qiTrans( mTransaction->QuerySpdyConnectTransaction()); MOZ_ASSERT(qiTrans); - qiTrans->MapStreamToHttpConnection( + return qiTrans->MapStreamToHttpConnection( mSocketTransport, mTransaction->ConnectionInfo(), aFlat407Headers, mIsTunnel ? aHttpResponseCode : -1); } diff --git a/netwerk/protocol/http/Http2Stream.h b/netwerk/protocol/http/Http2Stream.h index 6886131fa78d..157335664129 100644 --- a/netwerk/protocol/http/Http2Stream.h +++ b/netwerk/protocol/http/Http2Stream.h @@ -374,7 +374,7 @@ class Http2Stream : public nsAHttpSegmentReader, private: void ClearTransactionsBlockedOnTunnel(); void MapStreamToPlainText(); - void MapStreamToHttpConnection(const nsACString& aFlat407Headers, + bool MapStreamToHttpConnection(const nsACString& aFlat407Headers, int32_t aHttpResponseCode = -1); bool mIsTunnel; diff --git a/netwerk/protocol/http/TunnelUtils.cpp b/netwerk/protocol/http/TunnelUtils.cpp index 06eb9fb043d1..6e3062ff8b1c 100644 --- a/netwerk/protocol/http/TunnelUtils.cpp +++ b/netwerk/protocol/http/TunnelUtils.cpp @@ -1157,7 +1157,7 @@ void SpdyConnectTransaction::ForcePlainText() { mForcePlainText = true; } -void SpdyConnectTransaction::MapStreamToHttpConnection( +bool SpdyConnectTransaction::MapStreamToHttpConnection( nsISocketTransport* aTransport, nsHttpConnectionInfo* aConnInfo, const nsACString& aFlat407Headers, int32_t aHttpResponseCode) { MOZ_ASSERT(OnSocketThread()); @@ -1167,7 +1167,7 @@ void SpdyConnectTransaction::MapStreamToHttpConnection( ("SpdyConnectTransaction::MapStreamToHttpConnection %p skip " "pre-response with response code %d", this, aHttpResponseCode)); - return; + return false; } mConnInfo = aConnInfo; @@ -1233,6 +1233,8 @@ void SpdyConnectTransaction::MapStreamToHttpConnection( mDrivingTransaction, nsISupportsPriority::PRIORITY_HIGHEST - 60); mDrivingTransaction = nullptr; } + + return true; } nsresult SpdyConnectTransaction::Flush(uint32_t count, uint32_t* countRead) { diff --git a/netwerk/protocol/http/TunnelUtils.h b/netwerk/protocol/http/TunnelUtils.h index 2c5c8b6cd45a..78a9539c493e 100644 --- a/netwerk/protocol/http/TunnelUtils.h +++ b/netwerk/protocol/http/TunnelUtils.h @@ -221,7 +221,9 @@ class SpdyConnectTransaction final : public NullHttpTransaction { // CONNECT tunnel but the setup fails. The plaintext only carries the CONNECT // error. void ForcePlainText(); - void MapStreamToHttpConnection(nsISocketTransport* aTransport, + // True if we successfully map stream to a nsHttpConnection. Currently we skip + // 1xx response only. + bool MapStreamToHttpConnection(nsISocketTransport* aTransport, nsHttpConnectionInfo* aConnInfo, const nsACString& aFlat407Headers, int32_t aHttpResponseCode);