QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 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/third_party/quiche/src/http2/http2_structures.h" |
| 6 | |
| 7 | #include <cstring> // For std::memcmp |
| 8 | #include <sstream> |
| 9 | |
| 10 | #include "net/third_party/quiche/src/http2/platform/api/http2_string_utils.h" |
bnc | 252403d | 2020-01-15 08:39:53 -0800 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 12 | |
| 13 | namespace http2 { |
| 14 | |
| 15 | // Http2FrameHeader: |
| 16 | |
| 17 | bool Http2FrameHeader::IsProbableHttpResponse() const { |
| 18 | return (payload_length == 0x485454 && // "HTT" |
| 19 | static_cast<char>(type) == 'P' && // "P" |
| 20 | flags == '/'); // "/" |
| 21 | } |
| 22 | |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 23 | std::string Http2FrameHeader::ToString() const { |
bnc | 252403d | 2020-01-15 08:39:53 -0800 | [diff] [blame] | 24 | return quiche::QuicheStrCat( |
| 25 | "length=", payload_length, ", type=", Http2FrameTypeToString(type), |
| 26 | ", flags=", FlagsToString(), ", stream=", stream_id); |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 27 | } |
| 28 | |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 29 | std::string Http2FrameHeader::FlagsToString() const { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 30 | return Http2FrameFlagsToString(type, flags); |
| 31 | } |
| 32 | |
| 33 | bool operator==(const Http2FrameHeader& a, const Http2FrameHeader& b) { |
| 34 | return a.payload_length == b.payload_length && a.stream_id == b.stream_id && |
| 35 | a.type == b.type && a.flags == b.flags; |
| 36 | } |
| 37 | |
| 38 | std::ostream& operator<<(std::ostream& out, const Http2FrameHeader& v) { |
| 39 | return out << v.ToString(); |
| 40 | } |
| 41 | |
| 42 | // Http2PriorityFields: |
| 43 | |
| 44 | bool operator==(const Http2PriorityFields& a, const Http2PriorityFields& b) { |
| 45 | return a.stream_dependency == b.stream_dependency && a.weight == b.weight; |
| 46 | } |
| 47 | |
bnc | 4790400 | 2019-08-16 11:49:48 -0700 | [diff] [blame] | 48 | std::string Http2PriorityFields::ToString() const { |
QUICHE team | fd50a40 | 2018-12-07 22:54:05 -0500 | [diff] [blame] | 49 | std::stringstream ss; |
| 50 | ss << "E=" << (is_exclusive ? "true" : "false") |
| 51 | << ", stream=" << stream_dependency |
| 52 | << ", weight=" << static_cast<uint32_t>(weight); |
| 53 | return ss.str(); |
| 54 | } |
| 55 | |
| 56 | std::ostream& operator<<(std::ostream& out, const Http2PriorityFields& v) { |
| 57 | return out << v.ToString(); |
| 58 | } |
| 59 | |
| 60 | // Http2RstStreamFields: |
| 61 | |
| 62 | bool operator==(const Http2RstStreamFields& a, const Http2RstStreamFields& b) { |
| 63 | return a.error_code == b.error_code; |
| 64 | } |
| 65 | |
| 66 | std::ostream& operator<<(std::ostream& out, const Http2RstStreamFields& v) { |
| 67 | return out << "error_code=" << v.error_code; |
| 68 | } |
| 69 | |
| 70 | // Http2SettingFields: |
| 71 | |
| 72 | bool operator==(const Http2SettingFields& a, const Http2SettingFields& b) { |
| 73 | return a.parameter == b.parameter && a.value == b.value; |
| 74 | } |
| 75 | std::ostream& operator<<(std::ostream& out, const Http2SettingFields& v) { |
| 76 | return out << "parameter=" << v.parameter << ", value=" << v.value; |
| 77 | } |
| 78 | |
| 79 | // Http2PushPromiseFields: |
| 80 | |
| 81 | bool operator==(const Http2PushPromiseFields& a, |
| 82 | const Http2PushPromiseFields& b) { |
| 83 | return a.promised_stream_id == b.promised_stream_id; |
| 84 | } |
| 85 | |
| 86 | std::ostream& operator<<(std::ostream& out, const Http2PushPromiseFields& v) { |
| 87 | return out << "promised_stream_id=" << v.promised_stream_id; |
| 88 | } |
| 89 | |
| 90 | // Http2PingFields: |
| 91 | |
| 92 | bool operator==(const Http2PingFields& a, const Http2PingFields& b) { |
| 93 | static_assert((sizeof a.opaque_bytes) == Http2PingFields::EncodedSize(), |
| 94 | "Why not the same size?"); |
| 95 | return 0 == |
| 96 | std::memcmp(a.opaque_bytes, b.opaque_bytes, sizeof a.opaque_bytes); |
| 97 | } |
| 98 | |
| 99 | std::ostream& operator<<(std::ostream& out, const Http2PingFields& v) { |
| 100 | return out << "opaque_bytes=0x" |
| 101 | << Http2HexEncode(v.opaque_bytes, sizeof v.opaque_bytes); |
| 102 | } |
| 103 | |
| 104 | // Http2GoAwayFields: |
| 105 | |
| 106 | bool operator==(const Http2GoAwayFields& a, const Http2GoAwayFields& b) { |
| 107 | return a.last_stream_id == b.last_stream_id && a.error_code == b.error_code; |
| 108 | } |
| 109 | std::ostream& operator<<(std::ostream& out, const Http2GoAwayFields& v) { |
| 110 | return out << "last_stream_id=" << v.last_stream_id |
| 111 | << ", error_code=" << v.error_code; |
| 112 | } |
| 113 | |
| 114 | // Http2WindowUpdateFields: |
| 115 | |
| 116 | bool operator==(const Http2WindowUpdateFields& a, |
| 117 | const Http2WindowUpdateFields& b) { |
| 118 | return a.window_size_increment == b.window_size_increment; |
| 119 | } |
| 120 | std::ostream& operator<<(std::ostream& out, const Http2WindowUpdateFields& v) { |
| 121 | return out << "window_size_increment=" << v.window_size_increment; |
| 122 | } |
| 123 | |
| 124 | // Http2AltSvcFields: |
| 125 | |
| 126 | bool operator==(const Http2AltSvcFields& a, const Http2AltSvcFields& b) { |
| 127 | return a.origin_length == b.origin_length; |
| 128 | } |
| 129 | std::ostream& operator<<(std::ostream& out, const Http2AltSvcFields& v) { |
| 130 | return out << "origin_length=" << v.origin_length; |
| 131 | } |
| 132 | |
| 133 | } // namespace http2 |