Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: net/http/http_server_properties.cc

Issue 2129973002: Serialize NPN_HTTP_2 as "h2" instead of "npn-h2". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_server_properties.h" 5 #include "net/http/http_server_properties.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "net/socket/ssl_client_socket.h" 10 #include "net/socket/ssl_client_socket.h"
11 #include "net/ssl/ssl_config.h" 11 #include "net/ssl/ssl_config.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 const char kAlternativeServiceHeader[] = "Alt-Svc"; 15 const char kAlternativeServiceHeader[] = "Alt-Svc";
16 16
17 namespace {
18
19 // The order of these strings much match the order of the enum definition
20 // for AlternateProtocol.
21 const char* const kAlternateProtocolStrings[] = {
22 "npn-spdy/3.1",
23 "npn-h2",
24 "quic"};
25
26 static_assert(arraysize(kAlternateProtocolStrings) ==
27 NUM_VALID_ALTERNATE_PROTOCOLS,
28 "kAlternateProtocolStrings has incorrect size");
29
30 } // namespace
31
32 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) { 17 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) {
33 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage, 18 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage,
34 ALTERNATE_PROTOCOL_USAGE_MAX); 19 ALTERNATE_PROTOCOL_USAGE_MAX);
35 } 20 }
36 21
37 void HistogramBrokenAlternateProtocolLocation( 22 void HistogramBrokenAlternateProtocolLocation(
38 BrokenAlternateProtocolLocation location){ 23 BrokenAlternateProtocolLocation location){
39 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location, 24 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location,
40 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX); 25 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX);
41 } 26 }
42 27
43 bool IsAlternateProtocolValid(AlternateProtocol protocol) { 28 bool IsAlternateProtocolValid(AlternateProtocol protocol) {
44 return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION && 29 return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION &&
45 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; 30 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION;
46 } 31 }
47 32
48 const char* AlternateProtocolToString(AlternateProtocol protocol) { 33 const char* AlternateProtocolToString(AlternateProtocol protocol) {
49 switch (protocol) { 34 switch (protocol) {
35 case QUIC:
36 return "quic";
37 case NPN_HTTP_2:
38 return "h2";
50 case NPN_SPDY_3_1: 39 case NPN_SPDY_3_1:
51 case NPN_HTTP_2: 40 return "npn-spdy/3.1";
52 case QUIC:
53 DCHECK(IsAlternateProtocolValid(protocol));
54 return kAlternateProtocolStrings[
55 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION];
56 case UNINITIALIZED_ALTERNATE_PROTOCOL: 41 case UNINITIALIZED_ALTERNATE_PROTOCOL:
57 return "Uninitialized"; 42 return "Uninitialized";
58 } 43 }
59 NOTREACHED(); 44 NOTREACHED();
60 return ""; 45 return "";
61 } 46 }
62 47
63 AlternateProtocol AlternateProtocolFromString(const std::string& str) { 48 AlternateProtocol AlternateProtocolFromString(const std::string& str) {
64 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION; 49 if (str == "quic")
65 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) { 50 return QUIC;
66 AlternateProtocol protocol = static_cast<AlternateProtocol>(i); 51 if (str == "h2")
67 if (str == AlternateProtocolToString(protocol)) 52 return NPN_HTTP_2;
68 return protocol; 53 // "npn-h2" is accepted here so that persisted settings with the old string
69 } 54 // can be loaded from disk. TODO(bnc): Remove around 2016 December.
55 if (str == "npn-h2")
56 return NPN_HTTP_2;
57 if (str == "npn-spdy/3.1")
58 return NPN_SPDY_3_1;
59
70 return UNINITIALIZED_ALTERNATE_PROTOCOL; 60 return UNINITIALIZED_ALTERNATE_PROTOCOL;
71 } 61 }
72 62
73 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { 63 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) {
74 switch (next_proto) { 64 switch (next_proto) {
75 case kProtoSPDY31: 65 case kProtoSPDY31:
76 return NPN_SPDY_3_1; 66 return NPN_SPDY_3_1;
77 case kProtoHTTP2: 67 case kProtoHTTP2:
78 return NPN_HTTP_2; 68 return NPN_HTTP_2;
79 case kProtoQUIC1SPDY3: 69 case kProtoQUIC1SPDY3:
(...skipping 24 matching lines...) Expand all
104 94
105 // static 95 // static
106 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { 96 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) {
107 ssl_config->alpn_protos.clear(); 97 ssl_config->alpn_protos.clear();
108 ssl_config->alpn_protos.push_back(kProtoHTTP11); 98 ssl_config->alpn_protos.push_back(kProtoHTTP11);
109 ssl_config->npn_protos.clear(); 99 ssl_config->npn_protos.clear();
110 ssl_config->npn_protos.push_back(kProtoHTTP11); 100 ssl_config->npn_protos.push_back(kProtoHTTP11);
111 } 101 }
112 102
113 } // namespace net 103 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698