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

Side by Side Diff: net/spdy/spdy_alt_svc_wire_format.cc

Issue 1407643005: Add quotation marks around probability value in Alternative Services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 2 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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/spdy/spdy_alt_svc_wire_format.h" 5 #include "net/spdy/spdy_alt_svc_wire_format.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 if (parameter_name.compare("v") == 0) { 141 if (parameter_name.compare("v") == 0) {
142 if (!ParsePositiveInteger16(parameter_value_begin, c, &version)) { 142 if (!ParsePositiveInteger16(parameter_value_begin, c, &version)) {
143 return false; 143 return false;
144 } 144 }
145 } else if (parameter_name.compare("ma") == 0) { 145 } else if (parameter_name.compare("ma") == 0) {
146 if (!ParsePositiveInteger32(parameter_value_begin, c, &max_age)) { 146 if (!ParsePositiveInteger32(parameter_value_begin, c, &max_age)) {
147 return false; 147 return false;
148 } 148 }
149 } else if (parameter_name.compare("p") == 0) { 149 } else if (parameter_name.compare("p") == 0) {
150 if (!ParseProbability(parameter_value_begin, c, &probability)) { 150 // Probability value is enclosed in quotation marks.
151 if (*parameter_value_begin != '"' || *(c - 1) != '"') {
152 return false;
153 }
154 if (!ParseProbability(parameter_value_begin + 1, c - 1, &probability)) {
151 return false; 155 return false;
152 } 156 }
153 } 157 }
154 } 158 }
155 altsvc_vector->push_back(AlternativeService(protocol_id, host, port, 159 altsvc_vector->push_back(AlternativeService(protocol_id, host, port,
156 version, max_age, probability)); 160 version, max_age, probability));
157 for (; c != value.end() && (*c == ' ' || *c == '\t' || *c == ','); ++c) { 161 for (; c != value.end() && (*c == ' ' || *c == '\t' || *c == ','); ++c) {
158 } 162 }
159 } 163 }
160 return true; 164 return true;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 value.push_back(c); 217 value.push_back(c);
214 } 218 }
215 base::StringAppendF(&value, ":%d\"", altsvc.port); 219 base::StringAppendF(&value, ":%d\"", altsvc.port);
216 if (altsvc.version != 0) { 220 if (altsvc.version != 0) {
217 base::StringAppendF(&value, "; v=%d", altsvc.version); 221 base::StringAppendF(&value, "; v=%d", altsvc.version);
218 } 222 }
219 if (altsvc.max_age != 86400) { 223 if (altsvc.max_age != 86400) {
220 base::StringAppendF(&value, "; ma=%d", altsvc.max_age); 224 base::StringAppendF(&value, "; ma=%d", altsvc.max_age);
221 } 225 }
222 if (altsvc.probability != 1.0) { 226 if (altsvc.probability != 1.0) {
223 base::StringAppendF(&value, "; p=%.2f", altsvc.probability); 227 base::StringAppendF(&value, "; p=\"%.2f\"", altsvc.probability);
224 } 228 }
225 } 229 }
226 return value; 230 return value;
227 } 231 }
228 232
229 // static 233 // static
230 void SpdyAltSvcWireFormat::SkipWhiteSpace(StringPiece::const_iterator* c, 234 void SpdyAltSvcWireFormat::SkipWhiteSpace(StringPiece::const_iterator* c,
231 StringPiece::const_iterator end) { 235 StringPiece::const_iterator end) {
232 for (; *c != end && (**c == ' ' || **c == '\t'); ++*c) { 236 for (; *c != end && (**c == ' ' || **c == '\t'); ++*c) {
233 } 237 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ++c; 347 ++c;
344 double place_value = 0.1; 348 double place_value = 0.1;
345 for (; c != end && isdigit(*c); ++c) { 349 for (; c != end && isdigit(*c); ++c) {
346 *probability += place_value * (*c - '0'); 350 *probability += place_value * (*c - '0');
347 place_value *= 0.1; 351 place_value *= 0.1;
348 } 352 }
349 return (c == end && *probability <= 1.0); 353 return (c == end && *probability <= 1.0);
350 } 354 }
351 355
352 } // namespace net 356 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_network_transaction_unittest.cc ('k') | net/spdy/spdy_alt_svc_wire_format_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698