| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/http2/http2_structures.h" | |
| 6 | |
| 7 #include <cstring> // For std::memcmp | |
| 8 #include <sstream> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 | |
| 14 using std::string; | |
| 15 using base::StringPiece; | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 // Http2FrameHeader: | |
| 20 | |
| 21 bool Http2FrameHeader::IsProbableHttpResponse() const { | |
| 22 return (payload_length == 0x485454 && // "HTT" | |
| 23 static_cast<char>(type) == 'P' && // "P" | |
| 24 flags == '/'); // "/" | |
| 25 } | |
| 26 | |
| 27 string Http2FrameHeader::ToString() const { | |
| 28 std::stringstream ss; | |
| 29 ss << "length=" << payload_length << ", type=" << Http2FrameTypeToString(type) | |
| 30 << ", flags=" << FlagsToString() << ", stream=" << stream_id; | |
| 31 return ss.str(); | |
| 32 } | |
| 33 | |
| 34 string Http2FrameHeader::FlagsToString() const { | |
| 35 return Http2FrameFlagsToString(type, flags); | |
| 36 } | |
| 37 | |
| 38 bool operator==(const Http2FrameHeader& a, const Http2FrameHeader& b) { | |
| 39 return a.payload_length == b.payload_length && a.stream_id == b.stream_id && | |
| 40 a.type == b.type && a.flags == b.flags; | |
| 41 } | |
| 42 | |
| 43 std::ostream& operator<<(std::ostream& out, const Http2FrameHeader& v) { | |
| 44 return out << v.ToString(); | |
| 45 } | |
| 46 | |
| 47 // Http2PriorityFields: | |
| 48 | |
| 49 bool operator==(const Http2PriorityFields& a, const Http2PriorityFields& b) { | |
| 50 return a.stream_dependency == b.stream_dependency && a.weight == b.weight; | |
| 51 } | |
| 52 | |
| 53 std::string Http2PriorityFields::ToString() const { | |
| 54 std::stringstream ss; | |
| 55 ss << "E=" << (is_exclusive ? "true" : "false") | |
| 56 << ", stream=" << stream_dependency | |
| 57 << ", weight=" << static_cast<uint32_t>(weight); | |
| 58 return ss.str(); | |
| 59 } | |
| 60 | |
| 61 std::ostream& operator<<(std::ostream& out, const Http2PriorityFields& v) { | |
| 62 return out << v.ToString(); | |
| 63 } | |
| 64 | |
| 65 // Http2RstStreamFields: | |
| 66 | |
| 67 bool operator==(const Http2RstStreamFields& a, const Http2RstStreamFields& b) { | |
| 68 return a.error_code == b.error_code; | |
| 69 } | |
| 70 | |
| 71 std::ostream& operator<<(std::ostream& out, const Http2RstStreamFields& v) { | |
| 72 return out << "error_code=" << v.error_code; | |
| 73 } | |
| 74 | |
| 75 // Http2SettingFields: | |
| 76 | |
| 77 bool operator==(const Http2SettingFields& a, const Http2SettingFields& b) { | |
| 78 return a.parameter == b.parameter && a.value == b.value; | |
| 79 } | |
| 80 std::ostream& operator<<(std::ostream& out, const Http2SettingFields& v) { | |
| 81 return out << "parameter=" << v.parameter << ", value=" << v.value; | |
| 82 } | |
| 83 | |
| 84 // Http2PushPromiseFields: | |
| 85 | |
| 86 bool operator==(const Http2PushPromiseFields& a, | |
| 87 const Http2PushPromiseFields& b) { | |
| 88 return a.promised_stream_id == b.promised_stream_id; | |
| 89 } | |
| 90 | |
| 91 std::ostream& operator<<(std::ostream& out, const Http2PushPromiseFields& v) { | |
| 92 return out << "promised_stream_id=" << v.promised_stream_id; | |
| 93 } | |
| 94 | |
| 95 // Http2PingFields: | |
| 96 | |
| 97 bool operator==(const Http2PingFields& a, const Http2PingFields& b) { | |
| 98 static_assert((sizeof a.opaque_data) == Http2PingFields::EncodedSize(), | |
| 99 "Why not the same size?"); | |
| 100 return 0 == std::memcmp(a.opaque_data, b.opaque_data, sizeof a.opaque_data); | |
| 101 } | |
| 102 | |
| 103 std::ostream& operator<<(std::ostream& out, const Http2PingFields& v) { | |
| 104 string s = base::HexEncode(v.opaque_data, sizeof v.opaque_data); | |
| 105 base::CollapseWhitespaceASCII(s, /*trim_sequences_with_line_breaks=*/false); | |
| 106 return out << "opaque_data=[" << s << "]"; | |
| 107 } | |
| 108 | |
| 109 // Http2GoAwayFields: | |
| 110 | |
| 111 bool operator==(const Http2GoAwayFields& a, const Http2GoAwayFields& b) { | |
| 112 return a.last_stream_id == b.last_stream_id && a.error_code == b.error_code; | |
| 113 } | |
| 114 std::ostream& operator<<(std::ostream& out, const Http2GoAwayFields& v) { | |
| 115 return out << "last_stream_id=" << v.last_stream_id | |
| 116 << ", error_code=" << v.error_code; | |
| 117 } | |
| 118 | |
| 119 // Http2WindowUpdateFields: | |
| 120 | |
| 121 bool operator==(const Http2WindowUpdateFields& a, | |
| 122 const Http2WindowUpdateFields& b) { | |
| 123 return a.window_size_increment == b.window_size_increment; | |
| 124 } | |
| 125 std::ostream& operator<<(std::ostream& out, const Http2WindowUpdateFields& v) { | |
| 126 return out << "window_size_increment=" << v.window_size_increment; | |
| 127 } | |
| 128 | |
| 129 // Http2AltSvcFields: | |
| 130 | |
| 131 bool operator==(const Http2AltSvcFields& a, const Http2AltSvcFields& b) { | |
| 132 return a.origin_length == b.origin_length; | |
| 133 } | |
| 134 std::ostream& operator<<(std::ostream& out, const Http2AltSvcFields& v) { | |
| 135 return out << "origin_length=" << v.origin_length; | |
| 136 } | |
| 137 | |
| 138 } // namespace net | |
| OLD | NEW |