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

Unified Diff: net/quic/spdy_utils.cc

Issue 1494403002: Adds a ParseTrailers method to SpdyUtils, with some basic validation of the header keys provided. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@108694474
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') | no next file » | 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 b0e948b45ac755a63b7f697c767d48a1380a1ead..6cfdc1e7a2649d63231b15daf2befd5dae6bcbc3 100644
--- a/net/quic/spdy_utils.cc
+++ b/net/quic/spdy_utils.cc
@@ -65,4 +65,44 @@ bool SpdyUtils::ParseHeaders(const char* data,
return true;
}
+// static
+bool SpdyUtils::ParseTrailers(const char* data,
+ uint32 data_len,
+ size_t* final_byte_offset,
+ SpdyHeaderBlock* trailers) {
+ SpdyFramer framer(HTTP2);
+ if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) ||
+ trailers->empty()) {
+ DVLOG(1) << "Request Trailers are invalid.";
+ return false; // Trailers were invalid.
+ }
+
+ // Pull out the :final-offset pseudo header which indicates the number of
+ // response body bytes expected.
+ auto it = trailers->find(":final-offset");
+ if (it == trailers->end() ||
+ !base::StringToSizeT(it->second, final_byte_offset)) {
+ DVLOG(1) << ":final-offset not present";
+ return false; // :final-offset key must be present.
+ }
+ // :final-offset header is no longer used.
+ trailers->erase(it->first);
+
+ // Trailers must not have empty keys, and must not contain pseudo headers.
+ for (const auto& trailer : *trailers) {
+ base::StringPiece key = trailer.first;
+ base::StringPiece value = trailer.second;
+ if (key.starts_with(":")) {
+ DVLOG(1) << "Trailers must not contain pseudo-header: '" << key << "','"
+ << value << "'.";
+ return false;
+ }
+
+ // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec.
+ }
+
+ DVLOG(1) << "Successfully parsed Trailers.";
+ return true;
+}
+
} // namespace net
« no previous file with comments | « net/quic/spdy_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698