blob: 3558331e505df8556ba91d2820d6407f7a3cbad9 [file] [log] [blame]
QUICHE teamfd50a402018-12-07 22:54:05 -05001// 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"
bnc252403d2020-01-15 08:39:53 -080011#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h"
QUICHE teamfd50a402018-12-07 22:54:05 -050012
13namespace http2 {
14
15// Http2FrameHeader:
16
17bool Http2FrameHeader::IsProbableHttpResponse() const {
18 return (payload_length == 0x485454 && // "HTT"
19 static_cast<char>(type) == 'P' && // "P"
20 flags == '/'); // "/"
21}
22
bnc47904002019-08-16 11:49:48 -070023std::string Http2FrameHeader::ToString() const {
bnc252403d2020-01-15 08:39:53 -080024 return quiche::QuicheStrCat(
25 "length=", payload_length, ", type=", Http2FrameTypeToString(type),
26 ", flags=", FlagsToString(), ", stream=", stream_id);
QUICHE teamfd50a402018-12-07 22:54:05 -050027}
28
bnc47904002019-08-16 11:49:48 -070029std::string Http2FrameHeader::FlagsToString() const {
QUICHE teamfd50a402018-12-07 22:54:05 -050030 return Http2FrameFlagsToString(type, flags);
31}
32
33bool 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
38std::ostream& operator<<(std::ostream& out, const Http2FrameHeader& v) {
39 return out << v.ToString();
40}
41
42// Http2PriorityFields:
43
44bool operator==(const Http2PriorityFields& a, const Http2PriorityFields& b) {
45 return a.stream_dependency == b.stream_dependency && a.weight == b.weight;
46}
47
bnc47904002019-08-16 11:49:48 -070048std::string Http2PriorityFields::ToString() const {
QUICHE teamfd50a402018-12-07 22:54:05 -050049 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
56std::ostream& operator<<(std::ostream& out, const Http2PriorityFields& v) {
57 return out << v.ToString();
58}
59
60// Http2RstStreamFields:
61
62bool operator==(const Http2RstStreamFields& a, const Http2RstStreamFields& b) {
63 return a.error_code == b.error_code;
64}
65
66std::ostream& operator<<(std::ostream& out, const Http2RstStreamFields& v) {
67 return out << "error_code=" << v.error_code;
68}
69
70// Http2SettingFields:
71
72bool operator==(const Http2SettingFields& a, const Http2SettingFields& b) {
73 return a.parameter == b.parameter && a.value == b.value;
74}
75std::ostream& operator<<(std::ostream& out, const Http2SettingFields& v) {
76 return out << "parameter=" << v.parameter << ", value=" << v.value;
77}
78
79// Http2PushPromiseFields:
80
81bool operator==(const Http2PushPromiseFields& a,
82 const Http2PushPromiseFields& b) {
83 return a.promised_stream_id == b.promised_stream_id;
84}
85
86std::ostream& operator<<(std::ostream& out, const Http2PushPromiseFields& v) {
87 return out << "promised_stream_id=" << v.promised_stream_id;
88}
89
90// Http2PingFields:
91
92bool 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
99std::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
106bool operator==(const Http2GoAwayFields& a, const Http2GoAwayFields& b) {
107 return a.last_stream_id == b.last_stream_id && a.error_code == b.error_code;
108}
109std::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
116bool operator==(const Http2WindowUpdateFields& a,
117 const Http2WindowUpdateFields& b) {
118 return a.window_size_increment == b.window_size_increment;
119}
120std::ostream& operator<<(std::ostream& out, const Http2WindowUpdateFields& v) {
121 return out << "window_size_increment=" << v.window_size_increment;
122}
123
124// Http2AltSvcFields:
125
126bool operator==(const Http2AltSvcFields& a, const Http2AltSvcFields& b) {
127 return a.origin_length == b.origin_length;
128}
129std::ostream& operator<<(std::ostream& out, const Http2AltSvcFields& v) {
130 return out << "origin_length=" << v.origin_length;
131}
132
133} // namespace http2