Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit e2f4ea0

Browse files
harjothkharaaduh95
authored andcommitted
doc: document http2 header constants
Signed-off-by: harjoth <harjoth.khara@gmail.com> PR-URL: #64548 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1aafd19 commit e2f4ea0

1 file changed

Lines changed: 145 additions & 6 deletions

File tree

β€Ždoc/api/http2.mdβ€Ž

Lines changed: 145 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,142 @@ client.close();
33643364
added: v8.4.0
33653365
-->
33663366

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+
33673503
#### Error codes for `RST_STREAM` and `GOAWAY`
33683504

33693505
| Value | Name | Constant |
@@ -3930,19 +4066,21 @@ API:
39304066
```mjs
39314067
import { createServer } from'node:http2';
39324068
constserver=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+
});
39364073
res.end('ok');
39374074
});
39384075
```
39394076

39404077
```cjs
39414078
consthttp2=require('node:http2');
39424079
constserver=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+
});
39464084
res.end('ok');
39474085
});
39484086
```
@@ -5033,6 +5171,7 @@ you need to implement any fall-back behavior yourself.
50335171
[HTTP/2 Settings Object]: #settings-object
50345172
[HTTP/2 Unencrypted]: https://http2.github.io/faq/#does-http2-require-encryption
50355173
[HTTPS]: https.md
5174+
[Invalid character handling in header names and values]: #invalid-character-handling-in-header-names-and-values
50365175
[Performance Observer]: perf_hooks.md
50375176
[RFC 7838]: https://tools.ietf.org/html/rfc7838
50385177
[RFC 8336]: https://tools.ietf.org/html/rfc8336

0 commit comments

Comments
Β (0)