Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Http2Frame.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
23#pragma once
24
25#include <cstdint>
26#include <memory>
27
28namespace sese::net::http {
29
30constexpr static uint8_t FRAME_FLAG_END_STREAM = 0x1;
31constexpr static uint8_t FRAME_FLAG_END_HEADERS = 0x4;
32constexpr static uint8_t FRAME_FLAG_PADDED = 0x8;
33constexpr static uint8_t FRAME_FLAG_PRIORITY = 0x20;
34
35constexpr static uint8_t FRAME_TYPE_DATA = 0x0;
36constexpr static uint8_t FRAME_TYPE_HEADERS = 0x1;
37constexpr static uint8_t FRAME_TYPE_PRIORITY = 0x2;
38constexpr static uint8_t FRAME_TYPE_RST_STREAM = 0x3;
39constexpr static uint8_t FRAME_TYPE_SETTINGS = 0x4;
40constexpr static uint8_t FRAME_TYPE_PUSH_PROMISE = 0x5;
41constexpr static uint8_t FRAME_TYPE_PING = 0x6;
42constexpr static uint8_t FRAME_TYPE_GOAWAY = 0x7;
43constexpr static uint8_t FRAME_TYPE_WINDOW_UPDATE = 0x8;
44constexpr static uint8_t FRAME_TYPE_CONTINUATION = 0x9;
45constexpr static uint8_t FRAME_TYPE_ALTSVC = 0xa;
46constexpr static uint8_t FRAME_TYPE_ORIGIN = 0xc;
47
48constexpr static uint8_t GOAWAY_NO_ERROR = 0x0;
49constexpr static uint8_t GOAWAY_PROTOCOL_ERROR = 0x1;
50constexpr static uint8_t GOAWAY_INTERNAL_ERROR = 0x2;
51constexpr static uint8_t GOAWAY_FLOW_CONTROL_ERROR = 0x3;
52constexpr static uint8_t GOAWAY_SETTINGS_TIMEOUT = 0x4;
53constexpr static uint8_t GOAWAY_STREAM_CLOSED = 0x5;
54constexpr static uint8_t GOAWAY_FRAME_SIZE_ERROR = 0x6;
55constexpr static uint8_t GOAWAY_REFUSED_STREAM = 0x7;
56constexpr static uint8_t GOAWAY_CANCEL = 0x8;
57constexpr static uint8_t GOAWAY_COMPRESSION_ERROR = 0x9;
58constexpr static uint8_t GOAWAY_CONNECT_ERROR = 0xa;
59constexpr static uint8_t GOAWAY_ENHANCE_YOUR_CALM = 0xb;
60constexpr static uint8_t GOAWAY_INADEQUATE_SECURITY = 0xc;
61constexpr static uint8_t GOAWAY_HTTP_1_1_REQUIRED = 0xd;
62
63constexpr static uint16_t SETTINGS_HEADER_TABLE_SIZE = 0x1;
64constexpr static uint16_t SETTINGS_ENABLE_PUSH = 0x2;
65constexpr static uint16_t SETTINGS_MAX_CONCURRENT_STREAMS = 0x3;
66constexpr static uint16_t SETTINGS_INITIAL_WINDOW_SIZE = 0x4;
67constexpr static uint16_t SETTINGS_MAX_FRAME_SIZE = 0x5;
68constexpr static uint16_t SETTINGS_MAX_HEADER_LIST_SIZE = 0x6;
69
70constexpr static uint8_t SETTINGS_FLAGS_ACK = 0x1;
71
72constexpr static auto MAGIC_STRING = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
73
76 uint32_t length;
77 uint8_t type;
78 uint8_t flags;
79 uint32_t ident;
80};
81
83struct Http2Frame {
84 using Ptr = std::unique_ptr<Http2Frame>;
85
86 uint32_t length;
87 uint8_t type;
88 uint8_t flags;
89 uint32_t ident;
90
91 std::unique_ptr<char []> frame;
92
93 explicit Http2Frame(size_t frame_size);
94
97 [[nodiscard]] char *getFrameBuffer() const;
98
101 [[nodiscard]] size_t getFrameLength() const;
102
105 [[nodiscard]] char *getFrameContentBuffer() const;
106
109 [[nodiscard]] size_t getFrameContentLength() const;
110
112 void buildFrameHeader() const;
113};
114
115} // namespace sese::net::http