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