1 /** 2 * Constants 3 * 4 * Copyright: 5 * (C) 2012-2015 Tatsuhiro Tsujikawa 6 * (C) 2014-2015 Etienne Cimon 7 * 8 * License: 9 * Distributed under the terms of the MIT license with an additional section 1.2 of the curl/libcurl project. 10 * Consult the provided LICENSE.md file for details 11 */ 12 module libhttp2.constants; 13 14 version(unittest) 15 const TEST_ALL = true; 16 else 17 const TEST_ALL = false; 18 const DEBUG = false; 19 20 /// Version of this library 21 const VERSION = "0.2.5"; 22 23 /// The protocol version identification string of this library supports. 24 /// This identifier is used if HTTP/2 is used over TLS. 25 const PROTOCOL_VERSION_ID = "h2"; 26 27 /** 28 * Use this to verify compatibility if dynamic linking is involved. 29 */ 30 struct LibInfo 31 { 32 int age = 1; // This is the version of this struct 33 string version_str = VERSION; 34 string proto_str = PROTOCOL_VERSION_ID; 35 } 36 37 public static LibInfo g_lib_info; 38 39 package: 40 41 /// Enables READ_FIRST_SETTINGS in Session 42 version(unittest) const ENABLE_FIRST_SETTING_CHECK = false; 43 else const ENABLE_FIRST_SETTING_CHECK = true; 44 /** 45 * The seriazlied form of ALPN protocol identifier this library 46 * supports. Notice that first byte is the length of following 47 * protocol identifier. This is the same wire format of `TLS ALPN 48 * extension <https://tools.ietf.org/html/rfc7301>`_. This is useful 49 * to process incoming ALPN tokens in wire format. 50 */ 51 const PROTOCOL_ALPN = `h2-14`; 52 53 const HTTP_1_1_ALPN = `http/1.1`; 54 55 /// The protocol version identification string of this library supports. 56 /// This identifier is used if HTTP/2 is used over cleartext TCP. 57 const CLEARTEXT_PROTOCOL_VERSION_ID = "h2c-14"; 58 59 /// The default weight of stream dependency. 60 const DEFAULT_WEIGHT = 16; 61 62 /// The maximum weight of stream dependency. 63 const MAX_WEIGHT = 256; 64 65 /// The minimum weight of stream dependency. 66 const MIN_WEIGHT = 1; 67 68 /// The maximum window size 69 const MAX_WINDOW_SIZE = int.max; 70 71 /// The initial window size for stream level flow control. 72 const INITIAL_WINDOW_SIZE = ushort.max; 73 74 /// The initial window size for connection level flow control. 75 const INITIAL_CONNECTION_WINDOW_SIZE = ushort.max; 76 77 /// Default maximum concurrent streams. 78 const INITIAL_MAX_CONCURRENT_STREAMS = ((1u << 31) - 1); 79 80 /// The default header table size. 81 const DEFAULT_HEADER_TABLE_SIZE = (1 << 12); 82 83 /// The client connection preface. 84 const CLIENT_CONNECTION_PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"; 85 86 /// Buffer length for inbound raw byte stream used in $(D Session.recv). 87 const INBOUND_BUFFER_LENGTH = 16384; 88 89 const INBOUND_NUM_IV = 7; 90 91 92 const STREAM_ID_MASK = ((1u << 31) - 1); 93 const PRI_GROUP_ID_MASK = ((1u << 31) - 1); 94 const PRIORITY_MASK = ((1u << 31) - 1); 95 const WINDOW_SIZE_INCREMENT_MASK = ((1u << 31) - 1); 96 const SETTINGS_ID_MASK = ((1 << 24) - 1); 97 98 /* The number of bytes of frame header. */ 99 const FRAME_HDLEN = 9; 100 101 const MAX_FRAME_SIZE_MAX = ((1 << 24) - 1); 102 const MAX_FRAME_SIZE_MIN = (1 << 14); 103 104 const MAX_PAYLOADLEN = 16384; 105 106 /* The one frame buffer length for tranmission. We may use several of 107 them to support CONTINUATION. To account for Pad Length field, we 108 allocate extra 1 byte, which saves extra large memcopying. */ 109 const FRAMEBUF_CHUNKLEN = (FRAME_HDLEN + 1 + MAX_PAYLOADLEN); 110 111 /// Number of inbound buffer 112 const FRAMEBUF_MAX_NUM = 5; 113 114 /// The default length of DATA frame payload. 115 const DATA_PAYLOADLEN = MAX_FRAME_SIZE_MIN; 116 117 /// Maximum headers payload length, calculated in compressed form. 118 /// This applies to transmission only. 119 const MAX_HEADERSLEN = 65536; 120 121 /// The number of bytes for each SETTINGS entry 122 const FRAME_SETTINGS_ENTRY_LENGTH = 6; 123 124 /// The maximum header table size in $(D Setting.HEADER_TABLE_SIZE) 125 const MAX_HEADER_TABLE_SIZE = ((1u << 31) - 1); 126 127 /// Length of priority related fields in HEADERS/PRIORITY frames 128 const PRIORITY_SPECLEN = 5; 129 130 /// Maximum length of padding in bytes. 131 const MAX_PADLEN = 256; 132 133 /// A bit higher weight for non-DATA frames 134 const OB_EX_WEIGHT = 300; 135 136 /// Higher weight for SETTINGS 137 const OB_SETTINGS_WEIGHT = 301; 138 139 /// Highest weight for PING 140 const OB_PING_WEIGHT = 302; 141 142 __gshared immutable immutable(char)[] VALID_HD_NAME_CHARS = [ 143 0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, 0 /* EOT */, 144 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, 0 /* BS */, 0 /* HT */, 145 0 /* LF */, 0 /* VT */, 0 /* FF */, 0 /* CR */, 0 /* SO */, 146 0 /* SI */, 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */, 147 0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, 0 /* CAN */, 148 0 /* EM */, 0 /* SUB */, 0 /* ESC */, 0 /* FS */, 0 /* GS */, 149 0 /* RS */, 0 /* US */, 0 /* SPC */, 1 /* ! */, 0 /* " */, 150 1 /* # */, 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */, 151 0 /* ( */, 0 /* ) */, 1 /* * */, 1 /* + */, 0 /* , */, 152 1 /* - */, 1 /* . */, 0 /* / */, 1 /* 0 */, 1 /* 1 */, 153 1 /* 2 */, 1 /* 3 */, 1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 154 1 /* 7 */, 1 /* 8 */, 1 /* 9 */, 0 /* : */, 0 /* ; */, 155 0 /* < */, 0 /* = */, 0 /* > */, 0 /* ? */, 0 /* @ */, 156 0 /* A */, 0 /* B */, 0 /* C */, 0 /* D */, 0 /* E */, 157 0 /* F */, 0 /* G */, 0 /* H */, 0 /* I */, 0 /* J */, 158 0 /* K */, 0 /* L */, 0 /* M */, 0 /* N */, 0 /* O */, 159 0 /* P */, 0 /* Q */, 0 /* R */, 0 /* S */, 0 /* T */, 160 0 /* U */, 0 /* V */, 0 /* W */, 0 /* X */, 0 /* Y */, 161 0 /* Z */, 0 /* [ */, 0 /* \ */, 0 /* ] */, 1 /* ^ */, 162 1 /* _ */, 1 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */, 163 1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, 1 /* h */, 164 1 /* i */, 1 /* j */, 1 /* k */, 1 /* l */, 1 /* m */, 165 1 /* n */, 1 /* o */, 1 /* p */, 1 /* q */, 1 /* r */, 166 1 /* s */, 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */, 167 1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */, 1 /* | */, 168 0 /* } */, 1 /* ~ */, 0 /* DEL */, 0 /* 0x80 */, 0 /* 0x81 */, 169 0 /* 0x82 */, 0 /* 0x83 */, 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 170 0 /* 0x87 */, 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */, 171 0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, 0 /* 0x90 */, 172 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, 0 /* 0x94 */, 0 /* 0x95 */, 173 0 /* 0x96 */, 0 /* 0x97 */, 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 174 0 /* 0x9b */, 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */, 175 0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, 0 /* 0xa4 */, 176 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, 0 /* 0xa8 */, 0 /* 0xa9 */, 177 0 /* 0xaa */, 0 /* 0xab */, 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 178 0 /* 0xaf */, 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */, 179 0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, 0 /* 0xb8 */, 180 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, 0 /* 0xbc */, 0 /* 0xbd */, 181 0 /* 0xbe */, 0 /* 0xbf */, 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 182 0 /* 0xc3 */, 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */, 183 0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, 0 /* 0xcc */, 184 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, 0 /* 0xd0 */, 0 /* 0xd1 */, 185 0 /* 0xd2 */, 0 /* 0xd3 */, 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 186 0 /* 0xd7 */, 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */, 187 0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, 0 /* 0xe0 */, 188 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, 0 /* 0xe4 */, 0 /* 0xe5 */, 189 0 /* 0xe6 */, 0 /* 0xe7 */, 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 190 0 /* 0xeb */, 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */, 191 0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, 0 /* 0xf4 */, 192 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, 0 /* 0xf8 */, 0 /* 0xf9 */, 193 0 /* 0xfa */, 0 /* 0xfb */, 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 194 0 /* 0xff */ 195 ]; 196 197 __gshared immutable const(ubyte)[] VALID_HD_VALUE_CHARS = [ 198 0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, 0 /* EOT */, 199 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, 0 /* BS */, 1 /* HT */, 200 0 /* LF */, 0 /* VT */, 0 /* FF */, 0 /* CR */, 0 /* SO */, 201 0 /* SI */, 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */, 202 0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, 0 /* CAN */, 203 0 /* EM */, 0 /* SUB */, 0 /* ESC */, 0 /* FS */, 0 /* GS */, 204 0 /* RS */, 0 /* US */, 1 /* SPC */, 1 /* ! */, 1 /* " */, 205 1 /* # */, 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */, 206 1 /* ( */, 1 /* ) */, 1 /* * */, 1 /* + */, 1 /* , */, 207 1 /* - */, 1 /* . */, 1 /* / */, 1 /* 0 */, 1 /* 1 */, 208 1 /* 2 */, 1 /* 3 */, 1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 209 1 /* 7 */, 1 /* 8 */, 1 /* 9 */, 1 /* : */, 1 /* ; */, 210 1 /* < */, 1 /* = */, 1 /* > */, 1 /* ? */, 1 /* @ */, 211 1 /* A */, 1 /* B */, 1 /* C */, 1 /* D */, 1 /* E */, 212 1 /* F */, 1 /* G */, 1 /* H */, 1 /* I */, 1 /* J */, 213 1 /* K */, 1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */, 214 1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */, 1 /* T */, 215 1 /* U */, 1 /* V */, 1 /* W */, 1 /* X */, 1 /* Y */, 216 1 /* Z */, 1 /* [ */, 1 /* \ */, 1 /* ] */, 1 /* ^ */, 217 1 /* _ */, 1 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */, 218 1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, 1 /* h */, 219 1 /* i */, 1 /* j */, 1 /* k */, 1 /* l */, 1 /* m */, 220 1 /* n */, 1 /* o */, 1 /* p */, 1 /* q */, 1 /* r */, 221 1 /* s */, 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */, 222 1 /* x */, 1 /* y */, 1 /* z */, 1 /* { */, 1 /* | */, 223 1 /* } */, 1 /* ~ */, 0 /* DEL */, 1 /* 0x80 */, 1 /* 0x81 */, 224 1 /* 0x82 */, 1 /* 0x83 */, 1 /* 0x84 */, 1 /* 0x85 */, 1 /* 0x86 */, 225 1 /* 0x87 */, 1 /* 0x88 */, 1 /* 0x89 */, 1 /* 0x8a */, 1 /* 0x8b */, 226 1 /* 0x8c */, 1 /* 0x8d */, 1 /* 0x8e */, 1 /* 0x8f */, 1 /* 0x90 */, 227 1 /* 0x91 */, 1 /* 0x92 */, 1 /* 0x93 */, 1 /* 0x94 */, 1 /* 0x95 */, 228 1 /* 0x96 */, 1 /* 0x97 */, 1 /* 0x98 */, 1 /* 0x99 */, 1 /* 0x9a */, 229 1 /* 0x9b */, 1 /* 0x9c */, 1 /* 0x9d */, 1 /* 0x9e */, 1 /* 0x9f */, 230 1 /* 0xa0 */, 1 /* 0xa1 */, 1 /* 0xa2 */, 1 /* 0xa3 */, 1 /* 0xa4 */, 231 1 /* 0xa5 */, 1 /* 0xa6 */, 1 /* 0xa7 */, 1 /* 0xa8 */, 1 /* 0xa9 */, 232 1 /* 0xaa */, 1 /* 0xab */, 1 /* 0xac */, 1 /* 0xad */, 1 /* 0xae */, 233 1 /* 0xaf */, 1 /* 0xb0 */, 1 /* 0xb1 */, 1 /* 0xb2 */, 1 /* 0xb3 */, 234 1 /* 0xb4 */, 1 /* 0xb5 */, 1 /* 0xb6 */, 1 /* 0xb7 */, 1 /* 0xb8 */, 235 1 /* 0xb9 */, 1 /* 0xba */, 1 /* 0xbb */, 1 /* 0xbc */, 1 /* 0xbd */, 236 1 /* 0xbe */, 1 /* 0xbf */, 1 /* 0xc0 */, 1 /* 0xc1 */, 1 /* 0xc2 */, 237 1 /* 0xc3 */, 1 /* 0xc4 */, 1 /* 0xc5 */, 1 /* 0xc6 */, 1 /* 0xc7 */, 238 1 /* 0xc8 */, 1 /* 0xc9 */, 1 /* 0xca */, 1 /* 0xcb */, 1 /* 0xcc */, 239 1 /* 0xcd */, 1 /* 0xce */, 1 /* 0xcf */, 1 /* 0xd0 */, 1 /* 0xd1 */, 240 1 /* 0xd2 */, 1 /* 0xd3 */, 1 /* 0xd4 */, 1 /* 0xd5 */, 1 /* 0xd6 */, 241 1 /* 0xd7 */, 1 /* 0xd8 */, 1 /* 0xd9 */, 1 /* 0xda */, 1 /* 0xdb */, 242 1 /* 0xdc */, 1 /* 0xdd */, 1 /* 0xde */, 1 /* 0xdf */, 1 /* 0xe0 */, 243 1 /* 0xe1 */, 1 /* 0xe2 */, 1 /* 0xe3 */, 1 /* 0xe4 */, 1 /* 0xe5 */, 244 1 /* 0xe6 */, 1 /* 0xe7 */, 1 /* 0xe8 */, 1 /* 0xe9 */, 1 /* 0xea */, 245 1 /* 0xeb */, 1 /* 0xec */, 1 /* 0xed */, 1 /* 0xee */, 1 /* 0xef */, 246 1 /* 0xf0 */, 1 /* 0xf1 */, 1 /* 0xf2 */, 1 /* 0xf3 */, 1 /* 0xf4 */, 247 1 /* 0xf5 */, 1 /* 0xf6 */, 1 /* 0xf7 */, 1 /* 0xf8 */, 1 /* 0xf9 */, 248 1 /* 0xfa */, 1 /* 0xfb */, 1 /* 0xfc */, 1 /* 0xfd */, 1 /* 0xfe */, 249 1 /* 0xff */ 250 ];