| Index: net/quic/spdy_utils.cc
|
| diff --git a/net/quic/spdy_utils.cc b/net/quic/spdy_utils.cc
|
| index d66c2004c26effc350ec59e869a34d3ac6ad44a9..b0e948b45ac755a63b7f697c767d48a1380a1ead 100644
|
| --- a/net/quic/spdy_utils.cc
|
| +++ b/net/quic/spdy_utils.cc
|
| @@ -4,12 +4,18 @@
|
|
|
| #include "net/quic/spdy_utils.h"
|
|
|
| +#include <vector>
|
| +
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/stl_util.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_split.h"
|
| #include "net/spdy/spdy_frame_builder.h"
|
| #include "net/spdy/spdy_framer.h"
|
| #include "net/spdy/spdy_protocol.h"
|
|
|
| using std::string;
|
| +using std::vector;
|
|
|
| namespace net {
|
|
|
| @@ -24,4 +30,39 @@ string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) {
|
| return string(block->data(), length);
|
| }
|
|
|
| +// static
|
| +bool SpdyUtils::ParseHeaders(const char* data,
|
| + uint32 data_len,
|
| + int* content_length,
|
| + SpdyHeaderBlock* headers) {
|
| + SpdyFramer framer(HTTP2);
|
| + if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) ||
|
| + headers->empty()) {
|
| + return false; // Headers were invalid.
|
| + }
|
| +
|
| + if (ContainsKey(*headers, "content-length")) {
|
| + // Check whether multiple values are consistent.
|
| + base::StringPiece content_length_header = (*headers)["content-length"];
|
| + vector<string> values =
|
| + base::SplitString(content_length_header, base::StringPiece("\0", 1),
|
| + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
| + for (const string& value : values) {
|
| + int new_value;
|
| + if (!base::StringToInt(value, &new_value) || new_value < 0) {
|
| + return false;
|
| + }
|
| + if (*content_length < 0) {
|
| + *content_length = new_value;
|
| + continue;
|
| + }
|
| + if (new_value != *content_length) {
|
| + return false;
|
| + }
|
| + }
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| } // namespace net
|
|
|