1// Flags: --expose-internals 2'use strict'; 3 4const common = require('../common'); 5if (!common.hasCrypto) 6 common.skip('missing crypto'); 7const assert = require('assert'); 8const { internalBinding } = require('internal/test/binding'); 9 10const binding = internalBinding('http2'); 11const http2 = require('http2'); 12 13assert(binding.Http2Session); 14assert.strictEqual(typeof binding.Http2Session, 'function'); 15 16const settings = http2.getDefaultSettings(); 17assert.strictEqual(settings.headerTableSize, 4096); 18assert.strictEqual(settings.enablePush, true); 19assert.strictEqual(settings.maxConcurrentStreams, 4294967295); 20assert.strictEqual(settings.initialWindowSize, 65535); 21assert.strictEqual(settings.maxFrameSize, 16384); 22 23assert.strictEqual(binding.nghttp2ErrorString(-517), 24 'GOAWAY has already been sent'); 25 26// Assert constants are present 27assert(binding.constants); 28assert.strictEqual(typeof binding.constants, 'object'); 29const constants = binding.constants; 30 31const expectedStatusCodes = { 32 HTTP_STATUS_CONTINUE: 100, 33 HTTP_STATUS_SWITCHING_PROTOCOLS: 101, 34 HTTP_STATUS_PROCESSING: 102, 35 HTTP_STATUS_EARLY_HINTS: 103, 36 HTTP_STATUS_OK: 200, 37 HTTP_STATUS_CREATED: 201, 38 HTTP_STATUS_ACCEPTED: 202, 39 HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION: 203, 40 HTTP_STATUS_NO_CONTENT: 204, 41 HTTP_STATUS_RESET_CONTENT: 205, 42 HTTP_STATUS_PARTIAL_CONTENT: 206, 43 HTTP_STATUS_MULTI_STATUS: 207, 44 HTTP_STATUS_ALREADY_REPORTED: 208, 45 HTTP_STATUS_IM_USED: 226, 46 HTTP_STATUS_MULTIPLE_CHOICES: 300, 47 HTTP_STATUS_MOVED_PERMANENTLY: 301, 48 HTTP_STATUS_FOUND: 302, 49 HTTP_STATUS_SEE_OTHER: 303, 50 HTTP_STATUS_NOT_MODIFIED: 304, 51 HTTP_STATUS_USE_PROXY: 305, 52 HTTP_STATUS_TEMPORARY_REDIRECT: 307, 53 HTTP_STATUS_PERMANENT_REDIRECT: 308, 54 HTTP_STATUS_BAD_REQUEST: 400, 55 HTTP_STATUS_UNAUTHORIZED: 401, 56 HTTP_STATUS_PAYMENT_REQUIRED: 402, 57 HTTP_STATUS_FORBIDDEN: 403, 58 HTTP_STATUS_NOT_FOUND: 404, 59 HTTP_STATUS_METHOD_NOT_ALLOWED: 405, 60 HTTP_STATUS_NOT_ACCEPTABLE: 406, 61 HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED: 407, 62 HTTP_STATUS_REQUEST_TIMEOUT: 408, 63 HTTP_STATUS_CONFLICT: 409, 64 HTTP_STATUS_GONE: 410, 65 HTTP_STATUS_LENGTH_REQUIRED: 411, 66 HTTP_STATUS_PRECONDITION_FAILED: 412, 67 HTTP_STATUS_PAYLOAD_TOO_LARGE: 413, 68 HTTP_STATUS_URI_TOO_LONG: 414, 69 HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE: 415, 70 HTTP_STATUS_RANGE_NOT_SATISFIABLE: 416, 71 HTTP_STATUS_EXPECTATION_FAILED: 417, 72 HTTP_STATUS_TEAPOT: 418, 73 HTTP_STATUS_MISDIRECTED_REQUEST: 421, 74 HTTP_STATUS_UNPROCESSABLE_ENTITY: 422, 75 HTTP_STATUS_LOCKED: 423, 76 HTTP_STATUS_FAILED_DEPENDENCY: 424, 77 HTTP_STATUS_TOO_EARLY: 425, 78 HTTP_STATUS_UPGRADE_REQUIRED: 426, 79 HTTP_STATUS_PRECONDITION_REQUIRED: 428, 80 HTTP_STATUS_TOO_MANY_REQUESTS: 429, 81 HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE: 431, 82 HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS: 451, 83 HTTP_STATUS_INTERNAL_SERVER_ERROR: 500, 84 HTTP_STATUS_NOT_IMPLEMENTED: 501, 85 HTTP_STATUS_BAD_GATEWAY: 502, 86 HTTP_STATUS_SERVICE_UNAVAILABLE: 503, 87 HTTP_STATUS_GATEWAY_TIMEOUT: 504, 88 HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED: 505, 89 HTTP_STATUS_VARIANT_ALSO_NEGOTIATES: 506, 90 HTTP_STATUS_INSUFFICIENT_STORAGE: 507, 91 HTTP_STATUS_LOOP_DETECTED: 508, 92 HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED: 509, 93 HTTP_STATUS_NOT_EXTENDED: 510, 94 HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED: 511 95}; 96 97const expectedHeaderNames = { 98 HTTP2_HEADER_STATUS: ':status', 99 HTTP2_HEADER_METHOD: ':method', 100 HTTP2_HEADER_AUTHORITY: ':authority', 101 HTTP2_HEADER_SCHEME: ':scheme', 102 HTTP2_HEADER_PATH: ':path', 103 HTTP2_HEADER_PROTOCOL: ':protocol', 104 HTTP2_HEADER_DATE: 'date', 105 HTTP2_HEADER_ACCEPT_CHARSET: 'accept-charset', 106 HTTP2_HEADER_ACCEPT_ENCODING: 'accept-encoding', 107 HTTP2_HEADER_ACCEPT_LANGUAGE: 'accept-language', 108 HTTP2_HEADER_ACCEPT_RANGES: 'accept-ranges', 109 HTTP2_HEADER_ACCEPT: 'accept', 110 HTTP2_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS: 'access-control-allow-credentials', 111 HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS: 'access-control-allow-headers', 112 HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS: 'access-control-allow-methods', 113 HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN: 'access-control-allow-origin', 114 HTTP2_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS: 'access-control-expose-headers', 115 HTTP2_HEADER_ACCESS_CONTROL_MAX_AGE: 'access-control-max-age', 116 HTTP2_HEADER_ACCESS_CONTROL_REQUEST_HEADERS: 'access-control-request-headers', 117 HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD: 'access-control-request-method', 118 HTTP2_HEADER_AGE: 'age', 119 HTTP2_HEADER_ALLOW: 'allow', 120 HTTP2_HEADER_AUTHORIZATION: 'authorization', 121 HTTP2_HEADER_CACHE_CONTROL: 'cache-control', 122 HTTP2_HEADER_CONTENT_DISPOSITION: 'content-disposition', 123 HTTP2_HEADER_CONTENT_ENCODING: 'content-encoding', 124 HTTP2_HEADER_CONTENT_LANGUAGE: 'content-language', 125 HTTP2_HEADER_CONTENT_LENGTH: 'content-length', 126 HTTP2_HEADER_CONTENT_LOCATION: 'content-location', 127 HTTP2_HEADER_CONTENT_RANGE: 'content-range', 128 HTTP2_HEADER_CONTENT_TYPE: 'content-type', 129 HTTP2_HEADER_COOKIE: 'cookie', 130 HTTP2_HEADER_CONNECTION: 'connection', 131 HTTP2_HEADER_DNT: 'dnt', 132 HTTP2_HEADER_ETAG: 'etag', 133 HTTP2_HEADER_EXPECT: 'expect', 134 HTTP2_HEADER_EXPIRES: 'expires', 135 HTTP2_HEADER_FORWARDED: 'forwarded', 136 HTTP2_HEADER_FROM: 'from', 137 HTTP2_HEADER_HOST: 'host', 138 HTTP2_HEADER_IF_MATCH: 'if-match', 139 HTTP2_HEADER_IF_MODIFIED_SINCE: 'if-modified-since', 140 HTTP2_HEADER_IF_NONE_MATCH: 'if-none-match', 141 HTTP2_HEADER_IF_RANGE: 'if-range', 142 HTTP2_HEADER_IF_UNMODIFIED_SINCE: 'if-unmodified-since', 143 HTTP2_HEADER_LAST_MODIFIED: 'last-modified', 144 HTTP2_HEADER_LINK: 'link', 145 HTTP2_HEADER_LOCATION: 'location', 146 HTTP2_HEADER_MAX_FORWARDS: 'max-forwards', 147 HTTP2_HEADER_PREFER: 'prefer', 148 HTTP2_HEADER_PROXY_AUTHENTICATE: 'proxy-authenticate', 149 HTTP2_HEADER_PROXY_AUTHORIZATION: 'proxy-authorization', 150 HTTP2_HEADER_PROXY_CONNECTION: 'proxy-connection', 151 HTTP2_HEADER_RANGE: 'range', 152 HTTP2_HEADER_REFERER: 'referer', 153 HTTP2_HEADER_REFRESH: 'refresh', 154 HTTP2_HEADER_RETRY_AFTER: 'retry-after', 155 HTTP2_HEADER_SERVER: 'server', 156 HTTP2_HEADER_SET_COOKIE: 'set-cookie', 157 HTTP2_HEADER_STRICT_TRANSPORT_SECURITY: 'strict-transport-security', 158 HTTP2_HEADER_TRAILER: 'trailer', 159 HTTP2_HEADER_TRANSFER_ENCODING: 'transfer-encoding', 160 HTTP2_HEADER_TK: 'tk', 161 HTTP2_HEADER_UPGRADE_INSECURE_REQUESTS: 'upgrade-insecure-requests', 162 HTTP2_HEADER_USER_AGENT: 'user-agent', 163 HTTP2_HEADER_VARY: 'vary', 164 HTTP2_HEADER_VIA: 'via', 165 HTTP2_HEADER_WARNING: 'warning', 166 HTTP2_HEADER_WWW_AUTHENTICATE: 'www-authenticate', 167 HTTP2_HEADER_X_CONTENT_TYPE_OPTIONS: 'x-content-type-options', 168 HTTP2_HEADER_X_FRAME_OPTIONS: 'x-frame-options', 169 HTTP2_HEADER_KEEP_ALIVE: 'keep-alive', 170 HTTP2_HEADER_CONTENT_MD5: 'content-md5', 171 HTTP2_HEADER_TE: 'te', 172 HTTP2_HEADER_UPGRADE: 'upgrade', 173 HTTP2_HEADER_HTTP2_SETTINGS: 'http2-settings', 174 HTTP2_HEADER_X_XSS_PROTECTION: 'x-xss-protection', 175 HTTP2_HEADER_ALT_SVC: 'alt-svc', 176 HTTP2_HEADER_CONTENT_SECURITY_POLICY: 'content-security-policy', 177 HTTP2_HEADER_EARLY_DATA: 'early-data', 178 HTTP2_HEADER_EXPECT_CT: 'expect-ct', 179 HTTP2_HEADER_ORIGIN: 'origin', 180 HTTP2_HEADER_PURPOSE: 'purpose', 181 HTTP2_HEADER_TIMING_ALLOW_ORIGIN: 'timing-allow-origin', 182 HTTP2_HEADER_X_FORWARDED_FOR: 'x-forwarded-for', 183 HTTP2_HEADER_PRIORITY: 'priority', 184}; 185 186const expectedNGConstants = { 187 NGHTTP2_SESSION_SERVER: 0, 188 NGHTTP2_SESSION_CLIENT: 1, 189 NGHTTP2_STREAM_STATE_IDLE: 1, 190 NGHTTP2_STREAM_STATE_OPEN: 2, 191 NGHTTP2_STREAM_STATE_RESERVED_LOCAL: 3, 192 NGHTTP2_STREAM_STATE_RESERVED_REMOTE: 4, 193 NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL: 5, 194 NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE: 6, 195 NGHTTP2_STREAM_STATE_CLOSED: 7, 196 NGHTTP2_HCAT_REQUEST: 0, 197 NGHTTP2_HCAT_RESPONSE: 1, 198 NGHTTP2_HCAT_PUSH_RESPONSE: 2, 199 NGHTTP2_HCAT_HEADERS: 3, 200 NGHTTP2_NO_ERROR: 0, 201 NGHTTP2_PROTOCOL_ERROR: 1, 202 NGHTTP2_INTERNAL_ERROR: 2, 203 NGHTTP2_FLOW_CONTROL_ERROR: 3, 204 NGHTTP2_SETTINGS_TIMEOUT: 4, 205 NGHTTP2_STREAM_CLOSED: 5, 206 NGHTTP2_FRAME_SIZE_ERROR: 6, 207 NGHTTP2_REFUSED_STREAM: 7, 208 NGHTTP2_CANCEL: 8, 209 NGHTTP2_COMPRESSION_ERROR: 9, 210 NGHTTP2_CONNECT_ERROR: 10, 211 NGHTTP2_ENHANCE_YOUR_CALM: 11, 212 NGHTTP2_INADEQUATE_SECURITY: 12, 213 NGHTTP2_HTTP_1_1_REQUIRED: 13, 214 NGHTTP2_NV_FLAG_NONE: 0, 215 NGHTTP2_NV_FLAG_NO_INDEX: 1, 216 NGHTTP2_ERR_DEFERRED: -508, 217 NGHTTP2_ERR_NOMEM: -901, 218 NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE: -509, 219 NGHTTP2_ERR_INVALID_ARGUMENT: -501, 220 NGHTTP2_ERR_STREAM_CLOSED: -510, 221 NGHTTP2_ERR_FRAME_SIZE_ERROR: -522, 222 NGHTTP2_FLAG_NONE: 0, 223 NGHTTP2_FLAG_END_STREAM: 1, 224 NGHTTP2_FLAG_END_HEADERS: 4, 225 NGHTTP2_FLAG_ACK: 1, 226 NGHTTP2_FLAG_PADDED: 8, 227 NGHTTP2_FLAG_PRIORITY: 32, 228 NGHTTP2_DEFAULT_WEIGHT: 16, 229 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE: 1, 230 NGHTTP2_SETTINGS_ENABLE_PUSH: 2, 231 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS: 3, 232 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE: 4, 233 NGHTTP2_SETTINGS_MAX_FRAME_SIZE: 5, 234 NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE: 6, 235 NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL: 8 236}; 237 238const defaultSettings = { 239 DEFAULT_SETTINGS_HEADER_TABLE_SIZE: 4096, 240 DEFAULT_SETTINGS_ENABLE_PUSH: 1, 241 DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 4294967295, 242 DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 65535, 243 DEFAULT_SETTINGS_MAX_FRAME_SIZE: 16384, 244 DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: 65535, 245 DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL: 0 246}; 247 248for (const name of Object.keys(constants)) { 249 if (name.startsWith('HTTP_STATUS_')) { 250 assert.strictEqual(constants[name], expectedStatusCodes[name], 251 `Expected status code match for ${name}`); 252 } else if (name.startsWith('HTTP2_HEADER_')) { 253 assert.strictEqual(constants[name], expectedHeaderNames[name], 254 `Expected header name match for ${name}`); 255 } else if (name.startsWith('NGHTTP2_')) { 256 assert.strictEqual(constants[name], expectedNGConstants[name], 257 `Expected ng constant match for ${name}`); 258 } else if (name.startsWith('DEFAULT_SETTINGS_')) { 259 assert.strictEqual(constants[name], defaultSettings[name], 260 `Expected default setting match for ${name}`); 261 } 262} 263