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

Unified Diff: net/quic/spdy_utils.cc

Issue 1501493003: Pull HTTP/2 header parsing into utility method, from QuicSpdy{Client,Server}Streams. Not used in pr… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@108651883
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/spdy_utils.h ('k') | net/tools/quic/quic_spdy_client_stream.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « net/quic/spdy_utils.h ('k') | net/tools/quic/quic_spdy_client_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698