Add client connection option to disable server push in gQUIC.

Protected by connection option QNSP.

PiperOrigin-RevId: 326310589
Change-Id: I5f09591fc2ea3ae4381c34733e0c6e657dbf3520
diff --git a/quic/core/crypto/crypto_protocol.h b/quic/core/crypto/crypto_protocol.h
index 8d907d8..9bd5f17 100644
--- a/quic/core/crypto/crypto_protocol.h
+++ b/quic/core/crypto/crypto_protocol.h
@@ -355,6 +355,9 @@
                                                  // Encapsulation.
 const QuicTag kQNZR = TAG('Q', 'N', 'Z', 'R');   // Turn off QUIC crypto 0-RTT.
 
+const QuicTag kQNSP = TAG('Q', 'N', 'S', 'P');   // Turn off server push in
+                                                 // gQUIC.
+
 const QuicTag kMAD  = TAG('M', 'A', 'D', 0);     // Max Ack Delay (IETF QUIC)
 
 // Rejection tags
diff --git a/quic/core/http/quic_server_session_base.cc b/quic/core/http/quic_server_session_base.cc
index 805816e..c408257 100644
--- a/quic/core/http/quic_server_session_base.cc
+++ b/quic/core/http/quic_server_session_base.cc
@@ -9,6 +9,7 @@
 #include "net/third_party/quiche/src/quic/core/proto/cached_network_parameters_proto.h"
 #include "net/third_party/quiche/src/quic/core/quic_connection.h"
 #include "net/third_party/quiche/src/quic/core/quic_stream.h"
+#include "net/third_party/quiche/src/quic/core/quic_tag.h"
 #include "net/third_party/quiche/src/quic/core/quic_utils.h"
 #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h"
 #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h"
@@ -51,6 +52,12 @@
     return;
   }
 
+  // Disable server push if peer sends the corresponding connection option.
+  if (!version().UsesHttp3() &&
+      ContainsQuicTag(config()->ReceivedConnectionOptions(), kQNSP)) {
+    OnSetting(spdy::SETTINGS_ENABLE_PUSH, 0);
+  }
+
   // Enable bandwidth resumption if peer sent correct connection options.
   const bool last_bandwidth_resumption =
       ContainsQuicTag(config()->ReceivedConnectionOptions(), kBWRE);
diff --git a/quic/core/http/quic_server_session_base_test.cc b/quic/core/http/quic_server_session_base_test.cc
index 6af67a6..c37bacc 100644
--- a/quic/core/http/quic_server_session_base_test.cc
+++ b/quic/core/http/quic_server_session_base_test.cc
@@ -717,6 +717,20 @@
       QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get()));
 }
 
+TEST_P(QuicServerSessionBaseTest, TurnOffServerPush) {
+  if (session_->version().UsesHttp3()) {
+    return;
+  }
+
+  EXPECT_TRUE(session_->server_push_enabled());
+  QuicTagVector copt;
+  copt.push_back(kQNSP);
+  QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt);
+  connection_->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
+  session_->OnConfigNegotiated();
+  EXPECT_FALSE(session_->server_push_enabled());
+}
+
 // Tests which check the lifetime management of data members of
 // QuicCryptoServerStream objects when async GetProof is in use.
 class StreamMemberLifetimeTest : public QuicServerSessionBaseTest {