| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3364,6 +3364,142 @@ client.close(); | |||
| 3364 | 3364 | added: v8.4.0 | |
| 3365 | 3365 | --> | |
| 3366 | 3366 | ||
| 3367 | + #### Header name constants | ||
| 3368 | + | ||
| 3369 | + The `HTTP2_HEADER_*` constants provide names for HTTP/2 pseudo-headers and | ||
| 3370 | + known HTTP header names. Using these string constants is optional. For example, | ||
| 3371 | + `http2.constants.HTTP2_HEADER_CONTENT_TYPE` is equal to `'content-type'`. | ||
| 3372 | + For APIs that accept regular header names, | ||
| 3373 | + `http2.constants.HTTP2_HEADER_CONTENT_TYPE`, `'content-type'`, and | ||
| 3374 | + `'Content-Type'` have the same effect; Node.js serializes the name in | ||
| 3375 | + lower-case. | ||
| 3376 | + | ||
| 3377 | + Regular header constants can be used with the compatibility API wherever the | ||
| 3378 | + corresponding literal header name is accepted. In compatibility API request | ||
| 3379 | + handlers, prefer `request.method`, `request.authority`, `request.scheme`, and | ||
| 3380 | + `request.url` for the corresponding pseudo-headers. Other incoming | ||
| 3381 | + pseudo-headers remain available through `request.headers`. Set response status | ||
| 3382 | + through `response.statusCode` or the `statusCode` argument to | ||
| 3383 | + `response.writeHead()`. Passing `HTTP2_HEADER_STATUS` (`':status'`) to | ||
| 3384 | + `response.setHeader()` or in `response.writeHead()`'s headers object throws | ||
| 3385 | + `ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED`. `HTTP2_HEADER_PROTOCOL` is a request | ||
| 3386 | + pseudo-header and cannot be sent in a response. | ||
| 3387 | + | ||
| 3388 | + Incoming header object keys are lower-case, so use a constant or a lower-case | ||
| 3389 | + literal when accessing them as object properties. Using a constant does not | ||
| 3390 | + change header validation, and the availability of a constant does not imply | ||
| 3391 | + that the header is valid in every HTTP/2 context. See [HTTP/2 Headers Object][] | ||
| 3392 | + and [Invalid character handling in header names and values][] for details about | ||
| 3393 | + header casing and validation. | ||
| 3394 | + | ||
| 3395 | + ##### Pseudo-header constants | ||
| 3396 | + | ||
| 3397 | + `HTTP2_HEADER_METHOD`, `HTTP2_HEADER_AUTHORITY`, `HTTP2_HEADER_SCHEME`, and | ||
| 3398 | + `HTTP2_HEADER_PATH` identify request pseudo-headers. `HTTP2_HEADER_STATUS` | ||
| 3399 | + identifies the response pseudo-header. `HTTP2_HEADER_PROTOCOL` identifies the | ||
| 3400 | + extended `CONNECT` request pseudo-header. Pseudo-headers are not permitted in | ||
| 3401 | + trailers. | ||
| 3402 | + | ||
| 3403 | + | Constant | Value | | ||
| 3404 | + | ---------------------------------------- | -------------- | | ||
| 3405 | + | `http2.constants.HTTP2_HEADER_STATUS` | `':status'` | | ||
| 3406 | + | `http2.constants.HTTP2_HEADER_METHOD` | `':method'` | | ||
| 3407 | + | `http2.constants.HTTP2_HEADER_AUTHORITY` | `':authority'` | | ||
| 3408 | + | `http2.constants.HTTP2_HEADER_SCHEME` | `':scheme'` | | ||
| 3409 | + | `http2.constants.HTTP2_HEADER_PATH` | `':path'` | | ||
| 3410 | + | `http2.constants.HTTP2_HEADER_PROTOCOL` | `':protocol'` | | ||
| 3411 | + | ||
| 3412 | + ##### Regular header constants | ||
| 3413 | + | ||
| 3414 | + The `HTTP2_HEADER_CONNECTION`, `HTTP2_HEADER_UPGRADE`, | ||
| 3415 | + `HTTP2_HEADER_HTTP2_SETTINGS`, `HTTP2_HEADER_KEEP_ALIVE`, | ||
| 3416 | + `HTTP2_HEADER_PROXY_CONNECTION`, and `HTTP2_HEADER_TRANSFER_ENCODING` | ||
| 3417 | + constants identify connection-specific headers that HTTP/2 does not permit. | ||
| 3418 | + `HTTP2_HEADER_TE` is permitted only when its value is `'trailers'`. | ||
| 3419 | + | ||
| 3420 | + | Constant | Value | | ||
| 3421 | + | --------------------------------------------------------------- | ------------------------------------ | | ||
| 3422 | + | `http2.constants.HTTP2_HEADER_ACCEPT_ENCODING` | `'accept-encoding'` | | ||
| 3423 | + | `http2.constants.HTTP2_HEADER_ACCEPT_LANGUAGE` | `'accept-language'` | | ||
| 3424 | + | `http2.constants.HTTP2_HEADER_ACCEPT_RANGES` | `'accept-ranges'` | | ||
| 3425 | + | `http2.constants.HTTP2_HEADER_ACCEPT` | `'accept'` | | ||
| 3426 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS` | `'access-control-allow-credentials'` | | ||
| 3427 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS` | `'access-control-allow-headers'` | | ||
| 3428 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS` | `'access-control-allow-methods'` | | ||
| 3429 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN` | `'access-control-allow-origin'` | | ||
| 3430 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS` | `'access-control-expose-headers'` | | ||
| 3431 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_REQUEST_HEADERS` | `'access-control-request-headers'` | | ||
| 3432 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD` | `'access-control-request-method'` | | ||
| 3433 | + | `http2.constants.HTTP2_HEADER_AGE` | `'age'` | | ||
| 3434 | + | `http2.constants.HTTP2_HEADER_AUTHORIZATION` | `'authorization'` | | ||
| 3435 | + | `http2.constants.HTTP2_HEADER_CACHE_CONTROL` | `'cache-control'` | | ||
| 3436 | + | `http2.constants.HTTP2_HEADER_CONNECTION` | `'connection'` | | ||
| 3437 | + | `http2.constants.HTTP2_HEADER_CONTENT_DISPOSITION` | `'content-disposition'` | | ||
| 3438 | + | `http2.constants.HTTP2_HEADER_CONTENT_ENCODING` | `'content-encoding'` | | ||
| 3439 | + | `http2.constants.HTTP2_HEADER_CONTENT_LENGTH` | `'content-length'` | | ||
| 3440 | + | `http2.constants.HTTP2_HEADER_CONTENT_TYPE` | `'content-type'` | | ||
| 3441 | + | `http2.constants.HTTP2_HEADER_COOKIE` | `'cookie'` | | ||
| 3442 | + | `http2.constants.HTTP2_HEADER_DATE` | `'date'` | | ||
| 3443 | + | `http2.constants.HTTP2_HEADER_ETAG` | `'etag'` | | ||
| 3444 | + | `http2.constants.HTTP2_HEADER_FORWARDED` | `'forwarded'` | | ||
| 3445 | + | `http2.constants.HTTP2_HEADER_HOST` | `'host'` | | ||
| 3446 | + | `http2.constants.HTTP2_HEADER_IF_MODIFIED_SINCE` | `'if-modified-since'` | | ||
| 3447 | + | `http2.constants.HTTP2_HEADER_IF_NONE_MATCH` | `'if-none-match'` | | ||
| 3448 | + | `http2.constants.HTTP2_HEADER_IF_RANGE` | `'if-range'` | | ||
| 3449 | + | `http2.constants.HTTP2_HEADER_LAST_MODIFIED` | `'last-modified'` | | ||
| 3450 | + | `http2.constants.HTTP2_HEADER_LINK` | `'link'` | | ||
| 3451 | + | `http2.constants.HTTP2_HEADER_LOCATION` | `'location'` | | ||
| 3452 | + | `http2.constants.HTTP2_HEADER_RANGE` | `'range'` | | ||
| 3453 | + | `http2.constants.HTTP2_HEADER_REFERER` | `'referer'` | | ||
| 3454 | + | `http2.constants.HTTP2_HEADER_SERVER` | `'server'` | | ||
| 3455 | + | `http2.constants.HTTP2_HEADER_SET_COOKIE` | `'set-cookie'` | | ||
| 3456 | + | `http2.constants.HTTP2_HEADER_STRICT_TRANSPORT_SECURITY` | `'strict-transport-security'` | | ||
| 3457 | + | `http2.constants.HTTP2_HEADER_TRANSFER_ENCODING` | `'transfer-encoding'` | | ||
| 3458 | + | `http2.constants.HTTP2_HEADER_TE` | `'te'` | | ||
| 3459 | + | `http2.constants.HTTP2_HEADER_UPGRADE_INSECURE_REQUESTS` | `'upgrade-insecure-requests'` | | ||
| 3460 | + | `http2.constants.HTTP2_HEADER_UPGRADE` | `'upgrade'` | | ||
| 3461 | + | `http2.constants.HTTP2_HEADER_USER_AGENT` | `'user-agent'` | | ||
| 3462 | + | `http2.constants.HTTP2_HEADER_VARY` | `'vary'` | | ||
| 3463 | + | `http2.constants.HTTP2_HEADER_X_CONTENT_TYPE_OPTIONS` | `'x-content-type-options'` | | ||
| 3464 | + | `http2.constants.HTTP2_HEADER_X_FRAME_OPTIONS` | `'x-frame-options'` | | ||
| 3465 | + | `http2.constants.HTTP2_HEADER_KEEP_ALIVE` | `'keep-alive'` | | ||
| 3466 | + | `http2.constants.HTTP2_HEADER_PROXY_CONNECTION` | `'proxy-connection'` | | ||
| 3467 | + | `http2.constants.HTTP2_HEADER_X_XSS_PROTECTION` | `'x-xss-protection'` | | ||
| 3468 | + | `http2.constants.HTTP2_HEADER_ALT_SVC` | `'alt-svc'` | | ||
| 3469 | + | `http2.constants.HTTP2_HEADER_CONTENT_SECURITY_POLICY` | `'content-security-policy'` | | ||
| 3470 | + | `http2.constants.HTTP2_HEADER_EARLY_DATA` | `'early-data'` | | ||
| 3471 | + | `http2.constants.HTTP2_HEADER_EXPECT_CT` | `'expect-ct'` | | ||
| 3472 | + | `http2.constants.HTTP2_HEADER_ORIGIN` | `'origin'` | | ||
| 3473 | + | `http2.constants.HTTP2_HEADER_PURPOSE` | `'purpose'` | | ||
| 3474 | + | `http2.constants.HTTP2_HEADER_TIMING_ALLOW_ORIGIN` | `'timing-allow-origin'` | | ||
| 3475 | + | `http2.constants.HTTP2_HEADER_X_FORWARDED_FOR` | `'x-forwarded-for'` | | ||
| 3476 | + | `http2.constants.HTTP2_HEADER_PRIORITY` | `'priority'` | | ||
| 3477 | + | `http2.constants.HTTP2_HEADER_ACCEPT_CHARSET` | `'accept-charset'` | | ||
| 3478 | + | `http2.constants.HTTP2_HEADER_ACCESS_CONTROL_MAX_AGE` | `'access-control-max-age'` | | ||
| 3479 | + | `http2.constants.HTTP2_HEADER_ALLOW` | `'allow'` | | ||
| 3480 | + | `http2.constants.HTTP2_HEADER_CONTENT_LANGUAGE` | `'content-language'` | | ||
| 3481 | + | `http2.constants.HTTP2_HEADER_CONTENT_LOCATION` | `'content-location'` | | ||
| 3482 | + | `http2.constants.HTTP2_HEADER_CONTENT_MD5` | `'content-md5'` | | ||
| 3483 | + | `http2.constants.HTTP2_HEADER_CONTENT_RANGE` | `'content-range'` | | ||
| 3484 | + | `http2.constants.HTTP2_HEADER_DNT` | `'dnt'` | | ||
| 3485 | + | `http2.constants.HTTP2_HEADER_EXPECT` | `'expect'` | | ||
| 3486 | + | `http2.constants.HTTP2_HEADER_EXPIRES` | `'expires'` | | ||
| 3487 | + | `http2.constants.HTTP2_HEADER_FROM` | `'from'` | | ||
| 3488 | + | `http2.constants.HTTP2_HEADER_IF_MATCH` | `'if-match'` | | ||
| 3489 | + | `http2.constants.HTTP2_HEADER_IF_UNMODIFIED_SINCE` | `'if-unmodified-since'` | | ||
| 3490 | + | `http2.constants.HTTP2_HEADER_MAX_FORWARDS` | `'max-forwards'` | | ||
| 3491 | + | `http2.constants.HTTP2_HEADER_PREFER` | `'prefer'` | | ||
| 3492 | + | `http2.constants.HTTP2_HEADER_PROXY_AUTHENTICATE` | `'proxy-authenticate'` | | ||
| 3493 | + | `http2.constants.HTTP2_HEADER_PROXY_AUTHORIZATION` | `'proxy-authorization'` | | ||
| 3494 | + | `http2.constants.HTTP2_HEADER_REFRESH` | `'refresh'` | | ||
| 3495 | + | `http2.constants.HTTP2_HEADER_RETRY_AFTER` | `'retry-after'` | | ||
| 3496 | + | `http2.constants.HTTP2_HEADER_TRAILER` | `'trailer'` | | ||
| 3497 | + | `http2.constants.HTTP2_HEADER_TK` | `'tk'` | | ||
| 3498 | + | `http2.constants.HTTP2_HEADER_VIA` | `'via'` | | ||
| 3499 | + | `http2.constants.HTTP2_HEADER_WARNING` | `'warning'` | | ||
| 3500 | + | `http2.constants.HTTP2_HEADER_WWW_AUTHENTICATE` | `'www-authenticate'` | | ||
| 3501 | + | `http2.constants.HTTP2_HEADER_HTTP2_SETTINGS` | `'http2-settings'` | | ||
| 3502 | + | ||
| 3367 | 3503 | #### Error codes for `RST_STREAM` and `GOAWAY` | |
| 3368 | 3504 | ||
| 3369 | 3505 | | Value | Name | Constant | | |
@@ -3930,19 +4066,21 @@ API: | |||
| 3930 | 4066 | ```mjs | |
| 3931 | 4067 | import { createServer } from 'node:http2'; | |
| 3932 | 4068 | const server = createServer((req, res) => { | |
| 3933 | - res.setHeader('Content-Type', 'text/html'); | ||
| 3934 | - res.setHeader('X-Foo', 'bar'); | ||
| 3935 | - res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' }); | ||
| 4069 | + res.writeHead(200, { | ||
| 4070 | + 'Content-Type': 'text/plain; charset=utf-8', | ||
| 4071 | + 'X-Foo': 'bar', | ||
| 4072 | + }); | ||
| 3936 | 4073 | res.end('ok'); | |
| 3937 | 4074 | }); | |
| 3938 | 4075 | ``` | |
| 3939 | 4076 | ||
| 3940 | 4077 | ```cjs | |
| 3941 | 4078 | const http2 = require('node:http2'); | |
| 3942 | 4079 | const server = http2.createServer((req, res) => { | |
| 3943 | - res.setHeader('Content-Type', 'text/html'); | ||
| 3944 | - res.setHeader('X-Foo', 'bar'); | ||
| 3945 | - res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' }); | ||
| 4080 | + res.writeHead(200, { | ||
| 4081 | + 'Content-Type': 'text/plain; charset=utf-8', | ||
| 4082 | + 'X-Foo': 'bar', | ||
| 4083 | + }); | ||
| 3946 | 4084 | res.end('ok'); | |
| 3947 | 4085 | }); | |
| 3948 | 4086 | ``` | |
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself. | |||
| 5033 | 5171 | [HTTP/2 Settings Object]: #settings-object | |
| 5034 | 5172 | [HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption | |
| 5035 | 5173 | [HTTPS]: https.md | |
| 5174 | + [Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values | ||
| 5036 | 5175 | [Performance Observer]: perf_hooks.md | |
| 5037 | 5176 | [RFC 7838]: https://tools.ietf.org/html/rfc7838 | |
| 5038 | 5177 | [RFC 8336]: https://tools.ietf.org/html/rfc8336 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments