xref: /trafficserver/proxy/http3/Http3Types.h (revision 88909bcf)
1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "tscore/ink_platform.h"
27 
28 #include <memory>
29 
30 enum class Http3StreamType : uint8_t {
31   CONTROL       = 0x00, ///< HTTP/3
32   PUSH          = 0x01, ///< HTTP/3
33   QPACK_ENCODER = 0x02, ///< QPACK : encoder -> decoder
34   QPACK_DECODER = 0x03, ///< QPACK : decoder -> encoder
35   RESERVED      = 0x21,
36   UNKOWN        = 0xFF,
37 };
38 
39 enum class Http3SettingsId : uint64_t {
40   HEADER_TABLE_SIZE     = 0x01, ///< QPACK Settings
41   RESERVED_1            = 0x02, ///< HTTP/3 Settings
42   RESERVED_2            = 0x03, ///< HTTP/3 Settings
43   RESERVED_3            = 0x04, ///< HTTP/3 Settings
44   RESERVED_4            = 0x05, ///< HTTP/3 Settings
45   MAX_HEADER_LIST_SIZE  = 0x06, ///< HTTP/3 Settings
46   QPACK_BLOCKED_STREAMS = 0x07, ///< QPACK Settings
47   NUM_PLACEHOLDERS      = 0x09, ///< HTTP/3 Settings
48   UNKNOWN               = 0x0A0A,
49 };
50 
51 // Update Http3Frame::type(const uint8_t *) too when you modify this list
52 enum class Http3FrameType : uint64_t {
53   DATA              = 0x00,
54   HEADERS           = 0x01,
55   PRIORITY          = 0x02,
56   CANCEL_PUSH       = 0x03,
57   SETTINGS          = 0x04,
58   PUSH_PROMISE      = 0x05,
59   X_RESERVED_1      = 0x06,
60   GOAWAY            = 0x07,
61   X_RESERVED_2      = 0x08,
62   X_RESERVED_3      = 0x09,
63   MAX_PUSH_ID       = 0x0D,
64   DUPLICATE_PUSH_ID = 0x0E,
65   X_MAX_DEFINED     = 0x0E,
66   UNKNOWN           = 0xFF,
67 };
68 
69 enum class Http3ErrorClass {
70   NONE,
71   APPLICATION,
72 };
73 
74 // Actual error code of QPACK is not decided yet on qpack-05. It will be changed.
75 enum class Http3ErrorCode : uint16_t {
76   NO_ERROR                   = 0x0000,
77   WRONG_SETTING_DIRECTION    = 0x0001,
78   PUSH_REFUSED               = 0x0002,
79   INTERNAL_ERROR             = 0x0003,
80   PUSH_ALREADY_IN_CACHE      = 0x0004,
81   REQUEST_CANCELLED          = 0x0005,
82   INCOMPLETE_REQUEST         = 0x0006,
83   CONNECT_ERROR              = 0x0007,
84   EXCESSIVE_LOAD             = 0x0008,
85   VERSION_FALLBACK           = 0x0009,
86   WRONG_STREAM               = 0x000A,
87   LIMIT_EXCEEDED             = 0x000B,
88   DUPLICATE_PUSH             = 0x000C,
89   UNKNOWN_STREAM_TYPE        = 0x000D,
90   WRONG_STREAM_COUNT         = 0x000E,
91   CLOSED_CRITICAL_STREAM     = 0x000F,
92   WRONG_STREAM_DIRECTION     = 0x0010,
93   EARLY_RESPONSE             = 0x0011,
94   MISSING_SETTINGS           = 0x0012,
95   UNEXPECTED_FRAME           = 0x0013,
96   REQUEST_REJECTED           = 0x0014,
97   MALFORMED_FRAME            = 0x0100,
98   QPACK_DECOMPRESSION_FAILED = 0x200,
99   QPACK_ENCODER_STREAM_ERROR = 0x201,
100   QPACK_DECODER_STREAM_ERROR = 0x202,
101 };
102 
103 class Http3Error
104 {
105 public:
~Http3Error()106   virtual ~Http3Error() {}
107   uint16_t code();
108 
109   Http3ErrorClass cls = Http3ErrorClass::NONE;
110   union {
111     Http3ErrorCode app_error_code;
112   };
113   const char *msg = nullptr;
114 
115 protected:
Http3Error()116   Http3Error(){};
Http3Error(const Http3ErrorCode error_code,const char * error_msg=nullptr)117   Http3Error(const Http3ErrorCode error_code, const char *error_msg = nullptr)
118     : cls(Http3ErrorClass::APPLICATION), app_error_code(error_code), msg(error_msg){};
119 };
120 
121 class Http3NoError : public Http3Error
122 {
123 public:
Http3NoError()124   Http3NoError() : Http3Error() {}
125 };
126 
127 class Http3ConnectionError : public Http3Error
128 {
129 public:
Http3ConnectionError()130   Http3ConnectionError() : Http3Error() {}
Http3ConnectionError(const Http3ErrorCode error_code,const char * error_msg=nullptr)131   Http3ConnectionError(const Http3ErrorCode error_code, const char *error_msg = nullptr) : Http3Error(error_code, error_msg){};
132 };
133 
134 class Http3Stream
135 {
136 public:
137   static Http3StreamType type(const uint8_t *buf);
138 };
139 
140 class Http3StreamError : public Http3Error
141 {
142 public:
Http3StreamError()143   Http3StreamError() : Http3Error() {}
Http3StreamError(Http3Stream * s,const Http3ErrorCode error_code,const char * error_msg=nullptr)144   Http3StreamError(Http3Stream *s, const Http3ErrorCode error_code, const char *error_msg = nullptr)
145     : Http3Error(error_code, error_msg), stream(s){};
146 
147   Http3Stream *stream;
148 };
149 
150 using Http3ErrorUPtr           = std::unique_ptr<Http3Error>;
151 using Http3ConnectionErrorUPtr = std::unique_ptr<Http3ConnectionError>;
152 using Http3StreamErrorUPtr     = std::unique_ptr<Http3StreamError>;
153