• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HTTP2.h

Go to the documentation of this file.
00001 /** @file
00002  *
00003  *  Fundamental HTTP/2 protocol definitions and parsers.
00004  *
00005  *  @section license License
00006  *
00007  *  Licensed to the Apache Software Foundation (ASF) under one
00008  *  or more contributor license agreements.  See the NOTICE file
00009  *  distributed with this work for additional information
00010  *  regarding copyright ownership.  The ASF licenses this file
00011  *  to you under the Apache License, Version 2.0 (the
00012  *  "License"); you may not use this file except in compliance
00013  *  with the License.  You may obtain a copy of the License at
00014  *
00015  *      http://www.apache.org/licenses/LICENSE-2.0
00016  *
00017  *  Unless required by applicable law or agreed to in writing, software
00018  *  distributed under the License is distributed on an "AS IS" BASIS,
00019  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020  *  See the License for the specific language governing permissions and
00021  *  limitations under the License.
00022  */
00023 
00024 #ifndef __HTTP2_H__
00025 #define __HTTP2_H__
00026 
00027 #include "ink_defs.h"
00028 #include "ink_memory.h"
00029 
00030 typedef unsigned Http2StreamId;
00031 
00032 // 6.9.2 Initial Flow Control Window Size - the flow control window can be come negative
00033 // so we need to track it with a signed type.
00034 typedef int32_t Http2WindowSize;
00035 
00036 extern const char * const HTTP2_CONNECTION_PREFACE;
00037 const size_t HTTP2_CONNECTION_PREFACE_LEN = 24;
00038 
00039 const size_t HTTP2_FRAME_HEADER_LEN = 8;
00040 const size_t HTTP2_GOAWAY_LEN = 8;
00041 const size_t HTTP2_SETTINGS_PARAMETER_LEN = 5;
00042 
00043 // 4.2. Frame Size. The absolute maximum size of a frame payload is 2^14-1 (16,383) octets.
00044 const size_t HTTP2_MAX_FRAME_PAYLOAD = 16383;
00045 
00046 enum Http2ErrorCode
00047 {
00048   HTTP2_ERROR_NO_ERROR = 0,
00049   HTTP2_ERROR_PROTOCOL_ERROR = 1,
00050   HTTP2_ERROR_INTERNAL_ERROR = 2,
00051   HTTP2_ERROR_FLOW_CONTROL_ERROR = 3,
00052   HTTP2_ERROR_SETTINGS_TIMEOUT = 4,
00053   HTTP2_ERROR_STREAM_CLOSED = 5,
00054   HTTP2_ERROR_FRAME_SIZE_ERROR = 6,
00055   HTTP2_ERROR_REFUSED_STREAM = 7,
00056   HTTP2_ERROR_CANCEL = 8,
00057   HTTP2_ERROR_COMPRESSION_ERROR = 9,
00058   HTTP2_ERROR_CONNECT_ERROR = 10,
00059   HTTP2_ERROR_ENHANCE_YOUR_CALM = 11,
00060   HTTP2_ERROR_INADEQUATE_SECURITY = 12,
00061 
00062   HTTP2_ERROR_MAX,
00063 };
00064 
00065 enum Http2FrameType
00066 {
00067   HTTP2_FRAME_TYPE_DATA = 0,
00068   HTTP2_FRAME_TYPE_HEADERS = 1,
00069   HTTP2_FRAME_TYPE_PRIORITY = 2,
00070   HTTP2_FRAME_TYPE_RST_STREAM = 3,
00071   HTTP2_FRAME_TYPE_SETTINGS = 4,
00072   HTTP2_FRAME_TYPE_PUSH_PROMISE = 5,
00073   HTTP2_FRAME_TYPE_PING = 6,
00074   HTTP2_FRAME_TYPE_GOAWAY = 7,
00075   HTTP2_FRAME_TYPE_WINDOW_UPDATE = 8,
00076   HTTP2_FRAME_TYPE_CONTINUATION = 9,
00077   HTTP2_FRAME_TYPE_ALTSVC = 10,
00078   HTTP2_FRAME_TYPE_BLOCKED = 11,
00079 
00080   HTTP2_FRAME_TYPE_MAX,
00081 };
00082 
00083 // 6.1 Data
00084 enum Http2FrameFlagsData
00085 {
00086   HTTP2_FLAGS_DATA_END_STREAM = 0x01,
00087   HTTP2_FLAGS_DATA_END_SEGMENT = 0x02,
00088   HTTP2_FLAGS_DATA_PAD_LOW = 0x08,
00089   HTTP2_FLAGS_DATA_PAD_HIGH = 0x10,
00090   HTTP2_FLAGS_DATA_COMPRESSESD = 0x20,
00091 
00092   HTTP2_FLAGS_DATA_MASK = 0x2B,
00093 };
00094 
00095 // 6.2 Headers
00096 enum Http2FrameFlagsHeaders
00097 {
00098   HTTP2_FLAGS_HEADERS_END_STREAM = 0x01,
00099   HTTP2_FLAGS_HEADERS_END_SEGMENT = 0x02,
00100   HTTP2_FLAGS_HEADERS_PAD_LOW = 0x08,
00101   HTTP2_FLAGS_HEADERS_PAD_HIGH = 0x10,
00102   HTTP2_FLAGS_HEADERS_PRIORITY = 0x20,
00103 
00104   HTTP2_FLAGS_HEADERS_MASK = 0x2B,
00105 };
00106 
00107 // 6.3 Priority
00108 enum Http2FrameFlagsPriority
00109 {
00110   HTTP2_FLAGS_PRIORITY_MASK = 0x00
00111 };
00112 
00113 // 6.3 Rst Stream
00114 enum Http2FrameFlagsRstStream
00115 {
00116   HTTP2_FLAGS_RST_STREAM_MASK = 0x00
00117 };
00118 
00119 // 6.4 Settings
00120 enum Http2FrameFlagsSettings
00121 {
00122   HTTP2_FLAGS_SETTINGS_ACK = 0x01,
00123 
00124   HTTP2_FLAGS_SETTINGS_MASK = 0x01
00125 };
00126 
00127 // 6.6 Push Promise
00128 enum Http2FrameFlagsPushPromise
00129 {
00130   HTTP2_FLAGS_PUSH_PROMISE_END_HEADERS = 0x04,
00131   HTTP2_FLAGS_PUSH_PROMISE_PAD_LOW = 0x08,
00132   HTTP2_FLAGS_PUSH_PROMISE_PAD_HIGH = 0x10,
00133 
00134   HTTP2_FLAGS_PUSH_PROMISE_MASK = 0x1C,
00135 };
00136 
00137 // 6.7 Ping
00138 enum Http2FrameFlagsPing
00139 {
00140   HTTP2_FLAGS_PING_ACK = 0x01,
00141 
00142   HTTP2_FLAGS_PING_MASK = 0x01
00143 };
00144 
00145 // 6.8 Goaway
00146 enum Http2FrameFlagsGoaway
00147 {
00148   HTTP2_FLAGS_GOAWAY_MASK = 0x00
00149 };
00150 
00151 // 6.9 Window Update
00152 enum Http2FrameFlagsWindowUpdate
00153 {
00154   HTTP2_FLAGS_WINDOW_UPDATE_MASK = 0x00
00155 };
00156 
00157 // 6.10 Continuation
00158 enum Http2FrameFlagsContinuation
00159 {
00160   HTTP2_FLAGS_CONTINUATION_END_HEADERS = 0x04,
00161   HTTP2_FLAGS_CONTINUATION_PAD_LOW = 0x08,
00162   HTTP2_FLAGS_CONTINUATION_PAD_HIGH = 0x10,
00163 
00164   HTTP2_FLAGS_CONTINUATION_MASK = 0x1C,
00165 };
00166 
00167 // 6.11 Altsvc
00168 enum Http2FrameFlagsAltsvc
00169 {
00170   HTTP2_FLAGS_ALTSVC_MASK = 0x00
00171 };
00172 
00173 // 6.12 Blocked
00174 enum Http2FrameFlagsBlocked
00175 {
00176   HTTP2_FLAGS_BLOCKED_MASK = 0x00
00177 };
00178 
00179 // 6.5.2 Defined SETTINGS Parameters
00180 enum Http2SettingsIdentifier
00181 {
00182   HTTP2_SETTINGS_HEADER_TABLE_SIZE = 1,
00183   HTTP2_SETTINGS_ENABLE_PUSH = 2,
00184   HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 3,
00185   HTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 4,
00186   HTTP2_SETTINGS_COMPRESS_DATA = 5,
00187 
00188   HTTP2_SETTINGS_MAX
00189 };
00190 
00191 // 4.1. Frame Format
00192 struct Http2FrameHeader
00193 {
00194   uint16_t      length;
00195   uint8_t       type;
00196   uint8_t       flags;
00197   Http2StreamId streamid;
00198 };
00199 
00200 // 6.5.1. SETTINGS Format
00201 struct Http2SettingsParameter
00202 {
00203   uint8_t   id;
00204   uint32_t  value;
00205 };
00206 
00207 // 6.8 GOAWAY Format
00208 struct Http2Goaway
00209 {
00210   Http2StreamId last_streamid;
00211   uint32_t      error_code;
00212 
00213   // NOTE: we don't (de)serialize the variable length debug data at this layer because there's
00214   // really nothing we can do with it without some out of band agreement. Trying to deal with it
00215   // just complicates memory management.
00216 };
00217 
00218 // 6.9.1 The Flow Control Window
00219 static const Http2WindowSize HTTP2_MAX_WINDOW_SIZE = 0x7FFFFFFF;
00220 
00221 // 6.9.2 Initial Flow Control Window Size
00222 static const Http2WindowSize HTTP2_INITIAL_WINDOW_SIZE = 0x0000FFFF;
00223 
00224 static inline bool
00225 http2_is_client_streamid(Http2StreamId streamid) {
00226   return (streamid & 0x1u) == 0x1u;
00227 }
00228 
00229 static inline bool
00230 http2_is_server_streamid(Http2StreamId streamid) {
00231   return (streamid & 0x1u) == 0x0u;
00232 }
00233 
00234 bool
00235 http2_parse_frame_header(IOVec, Http2FrameHeader&);
00236 
00237 bool
00238 http2_write_frame_header(const Http2FrameHeader&, IOVec);
00239 
00240 bool
00241 http2_write_goaway(const Http2Goaway&, IOVec);
00242 
00243 bool
00244 http2_frame_header_is_valid(const Http2FrameHeader&);
00245 
00246 bool
00247 http2_settings_parameter_is_valid(const Http2SettingsParameter&);
00248 
00249 bool
00250 http2_parse_settings_parameter(IOVec, Http2SettingsParameter&);
00251 
00252 #endif /* __HTTP2_H__ */

Generated by  doxygen 1.7.1