summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorbnc <bnc@chromium.org>2015-10-12 20:59:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-13 04:00:40 +0000
commit0ddae6a9c18966d68768a792b766a3c9ce74d920 (patch)
tree1cc7d4d1fbd11d0108db3b771c5a0b9026a917c3 /net
parentbd081903b5e478d5d6b32daca4549d84a5203058 (diff)
downloadchromium_src-0ddae6a9c18966d68768a792b766a3c9ce74d920.zip
chromium_src-0ddae6a9c18966d68768a792b766a3c9ce74d920.tar.gz
chromium_src-0ddae6a9c18966d68768a792b766a3c9ce74d920.tar.bz2
Implement "clear" keyword in SpdyAltSvcWireFormat.
Note that the "clear" keyword was introduced to the Alternative Services specification in draft-08. This CL lands server change 104884972 by bnc. BUG=392575 Review URL: https://codereview.chromium.org/1402633003 Cr-Commit-Position: refs/heads/master@{#353672}
Diffstat (limited to 'net')
-rw-r--r--net/spdy/spdy_alt_svc_wire_format.cc10
-rw-r--r--net/spdy/spdy_alt_svc_wire_format.h5
-rw-r--r--net/spdy/spdy_alt_svc_wire_format_test.cc13
3 files changed, 24 insertions, 4 deletions
diff --git a/net/spdy/spdy_alt_svc_wire_format.cc b/net/spdy/spdy_alt_svc_wire_format.cc
index 4ac8dc5..ad414ff 100644
--- a/net/spdy/spdy_alt_svc_wire_format.cc
+++ b/net/spdy/spdy_alt_svc_wire_format.cc
@@ -54,7 +54,14 @@ SpdyAltSvcWireFormat::AlternativeService::AlternativeService(
bool SpdyAltSvcWireFormat::ParseHeaderFieldValue(
StringPiece value,
AlternativeServiceVector* altsvc_vector) {
+ // Empty value is invalid according to the specification.
+ if (value.empty()) {
+ return false;
+ }
altsvc_vector->clear();
+ if (value == StringPiece("clear")) {
+ return true;
+ }
StringPiece::const_iterator c = value.begin();
while (c != value.end()) {
// Parse protocol-id.
@@ -156,6 +163,9 @@ bool SpdyAltSvcWireFormat::ParseHeaderFieldValue(
// static
std::string SpdyAltSvcWireFormat::SerializeHeaderFieldValue(
const AlternativeServiceVector& altsvc_vector) {
+ if (altsvc_vector.empty()) {
+ return std::string("clear");
+ }
const char kNibbleToHex[] = "0123456789ABCDEF";
std::string value;
for (const AlternativeService& altsvc : altsvc_vector) {
diff --git a/net/spdy/spdy_alt_svc_wire_format.h b/net/spdy/spdy_alt_svc_wire_format.h
index 23d9187..8b8a0b1 100644
--- a/net/spdy/spdy_alt_svc_wire_format.h
+++ b/net/spdy/spdy_alt_svc_wire_format.h
@@ -5,7 +5,7 @@
// This file contains data structures and utility functions used for serializing
// and parsing alternative service header values, common to HTTP/1.1 header
// fields and HTTP/2 and QUIC ALTSVC frames. See specification at
-// https://tools.ietf.org/id/draft-ietf-httpbis-alt-svc-06.html
+// https://httpwg.github.io/http-extensions/alt-svc.html.
#ifndef NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_
#define NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_
@@ -52,6 +52,9 @@ class NET_EXPORT_PRIVATE SpdyAltSvcWireFormat {
max_age == other.max_age && p == other.p;
}
};
+ // An empty vector means alternative services should be cleared for given
+ // origin. Note that the wire format for this is the string "clear", not an
+ // empty value (which is invalid).
typedef std::vector<AlternativeService> AlternativeServiceVector;
friend class test::SpdyAltSvcWireFormatPeer;
diff --git a/net/spdy/spdy_alt_svc_wire_format_test.cc b/net/spdy/spdy_alt_svc_wire_format_test.cc
index 550d767..b53db3b 100644
--- a/net/spdy/spdy_alt_svc_wire_format_test.cc
+++ b/net/spdy/spdy_alt_svc_wire_format_test.cc
@@ -159,9 +159,15 @@ TEST(SpdyAltSvcWireFormatTest, DefaultValues) {
EXPECT_DOUBLE_EQ(1.0, altsvc.p);
}
-TEST(SpdyAltSvcWireFormatTest, ParseEmptyHeaderFieldValue) {
+TEST(SpdyAltSvcWireFormatTest, ParseInvalidEmptyHeaderFieldValue) {
SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector;
- ASSERT_TRUE(SpdyAltSvcWireFormat::ParseHeaderFieldValue("", &altsvc_vector));
+ ASSERT_FALSE(SpdyAltSvcWireFormat::ParseHeaderFieldValue("", &altsvc_vector));
+}
+
+TEST(SpdyAltSvcWireFormatTest, ParseHeaderFieldValueClear) {
+ SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector;
+ ASSERT_TRUE(
+ SpdyAltSvcWireFormat::ParseHeaderFieldValue("clear", &altsvc_vector));
EXPECT_EQ(0u, altsvc_vector.size());
}
@@ -220,7 +226,8 @@ TEST(SpdyAltSvcWireFormatTest, ParseHeaderFieldValueMultiple) {
TEST(SpdyAltSvcWireFormatTest, SerializeEmptyHeaderFieldValue) {
SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector;
- EXPECT_EQ("", SpdyAltSvcWireFormat::SerializeHeaderFieldValue(altsvc_vector));
+ EXPECT_EQ("clear",
+ SpdyAltSvcWireFormat::SerializeHeaderFieldValue(altsvc_vector));
}
// Test SerializeHeaderFieldValue() with and without hostname and each