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

Unified Diff: net/http2/http2_constants.cc

Issue 2293613002: Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Replace LOG(INFO) by VLOG(2) in DecodeBufferTest.SlowDecodeTestStruct so that trybots do not fail. Created 4 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/http2/http2_constants.h ('k') | net/http2/http2_constants_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http2/http2_constants.cc
diff --git a/net/http2/http2_constants.cc b/net/http2/http2_constants.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca28f15eb50cea8fd352cd95106c362c3d6ae803
--- /dev/null
+++ b/net/http2/http2_constants.cc
@@ -0,0 +1,161 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/http2/http2_constants.h"
+
+#include <ios>
+#include <sstream>
+
+#include "base/logging.h"
+#include "base/strings/string_piece.h"
+#include "base/strings/stringprintf.h"
+
+using base::StringPrintf;
+using std::string;
+
+namespace net {
+
+string Http2FrameTypeToString(Http2FrameType v) {
+ switch (v) {
+ case Http2FrameType::DATA:
+ return "DATA";
+ case Http2FrameType::HEADERS:
+ return "HEADERS";
+ case Http2FrameType::PRIORITY:
+ return "PRIORITY";
+ case Http2FrameType::RST_STREAM:
+ return "RST_STREAM";
+ case Http2FrameType::SETTINGS:
+ return "SETTINGS";
+ case Http2FrameType::PUSH_PROMISE:
+ return "PUSH_PROMISE";
+ case Http2FrameType::PING:
+ return "PING";
+ case Http2FrameType::GOAWAY:
+ return "GOAWAY";
+ case Http2FrameType::WINDOW_UPDATE:
+ return "WINDOW_UPDATE";
+ case Http2FrameType::CONTINUATION:
+ return "CONTINUATION";
+ case Http2FrameType::ALTSVC:
+ return "ALTSVC";
+ }
+ std::stringstream ss;
+ ss << "UnknownFrameType(" << static_cast<int>(v) << ")";
+ return ss.str();
+}
+string Http2FrameTypeToString(uint8_t v) {
+ return Http2FrameTypeToString(static_cast<Http2FrameType>(v));
+}
+
+string Http2FrameFlagsToString(Http2FrameType type, uint8_t flags) {
+ string s;
+ // Closure to append flag name |v| to the string |s|, and to clear
+ // |bit| from |flags|.
+ auto append_and_clear = [&s, &flags](base::StringPiece v, uint8_t bit) {
+ if (!s.empty()) {
+ s.push_back('|');
+ }
+ v.AppendToString(&s);
+ flags ^= bit;
+ };
+ if (flags & 0x01) {
+ if (type == Http2FrameType::DATA || type == Http2FrameType::HEADERS) {
+ append_and_clear("END_STREAM", Http2FrameFlag::FLAG_END_STREAM);
+ } else if (type == Http2FrameType::SETTINGS ||
+ type == Http2FrameType::PING) {
+ append_and_clear("ACK", Http2FrameFlag::FLAG_ACK);
+ }
+ }
+ if (flags & 0x04) {
+ if (type == Http2FrameType::HEADERS ||
+ type == Http2FrameType::PUSH_PROMISE ||
+ type == Http2FrameType::CONTINUATION) {
+ append_and_clear("END_HEADERS", Http2FrameFlag::FLAG_END_HEADERS);
+ }
+ }
+ if (flags & 0x08) {
+ if (type == Http2FrameType::DATA || type == Http2FrameType::HEADERS ||
+ type == Http2FrameType::PUSH_PROMISE) {
+ append_and_clear("PADDED", Http2FrameFlag::FLAG_PADDED);
+ }
+ }
+ if (flags & 0x20) {
+ if (type == Http2FrameType::HEADERS) {
+ append_and_clear("PRIORITY", Http2FrameFlag::FLAG_PRIORITY);
+ }
+ }
+ if (flags != 0) {
+ append_and_clear(StringPrintf("0x%02x", flags), flags);
+ }
+ DCHECK_EQ(0, flags);
+ return s;
+}
+string Http2FrameFlagsToString(uint8_t type, uint8_t flags) {
+ return Http2FrameFlagsToString(static_cast<Http2FrameType>(type), flags);
+}
+
+string Http2ErrorCodeToString(uint32_t v) {
+ switch (v) {
+ case 0x0:
+ return "NO_ERROR";
+ case 0x1:
+ return "PROTOCOL_ERROR";
+ case 0x2:
+ return "INTERNAL_ERROR";
+ case 0x3:
+ return "FLOW_CONTROL_ERROR";
+ case 0x4:
+ return "SETTINGS_TIMEOUT";
+ case 0x5:
+ return "STREAM_CLOSED";
+ case 0x6:
+ return "FRAME_SIZE_ERROR";
+ case 0x7:
+ return "REFUSED_STREAM";
+ case 0x8:
+ return "CANCEL";
+ case 0x9:
+ return "COMPRESSION_ERROR";
+ case 0xa:
+ return "CONNECT_ERROR";
+ case 0xb:
+ return "ENHANCE_YOUR_CALM";
+ case 0xc:
+ return "INADEQUATE_SECURITY";
+ case 0xd:
+ return "HTTP_1_1_REQUIRED";
+ }
+ std::stringstream ss;
+ ss << "UnknownErrorCode(0x" << std::hex << v << ")";
+ return ss.str();
+}
+string Http2ErrorCodeToString(Http2ErrorCode v) {
+ return Http2ErrorCodeToString(static_cast<uint32_t>(v));
+}
+
+string Http2SettingsParameterToString(uint32_t v) {
+ switch (v) {
+ case 0x1:
+ return "HEADER_TABLE_SIZE";
+ case 0x2:
+ return "ENABLE_PUSH";
+ case 0x3:
+ return "MAX_CONCURRENT_STREAMS";
+ case 0x4:
+ return "INITIAL_WINDOW_SIZE";
+ case 0x5:
+ return "MAX_FRAME_SIZE";
+ case 0x6:
+ return "MAX_HEADER_LIST_SIZE";
+ }
+ std::stringstream ss;
+ ss << "UnknownSettingsParameter(0x" << std::hex << v << ")";
+ return ss.str();
+}
+string Http2SettingsParameterToString(Http2SettingsParameter v) {
+ return Http2SettingsParameterToString(static_cast<uint32_t>(v));
+}
+
+} // namespace net
« no previous file with comments | « net/http2/http2_constants.h ('k') | net/http2/http2_constants_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698