|
2 | 2 | <!-- YAML
|
3 | 3 | added: v8.4.0
|
4 | 4 | changes:
|
| 5 | + - version: REPLACEME |
| 6 | + pr-url: REPLACEME |
| 7 | + description: Requests with the `host` header (with or without |
| 8 | + `:authority`) can now be sent / received. |
5 | 9 | - version: v10.10.0
|
6 | 10 | pr-url: https://github.com/nodejs/node/pull/22466
|
7 | 11 | description: HTTP/2 is now Stable. Previously, it had been Experimental.
|
@@ -2530,7 +2534,7 @@ For incoming headers:
|
2530 | 2534 | `access-control-max-age`, `access-control-request-method`, `content-encoding`,
|
2531 | 2535 | `content-language`, `content-length`, `content-location`, `content-md5`,
|
2532 | 2536 | `content-range`, `content-type`, `date`, `dnt`, `etag`, `expires`, `from`,
|
2533 |
| - `if-match`, `if-modified-since`, `if-none-match`, `if-range`, |
| 2537 | + `host`, `if-match`, `if-modified-since`, `if-none-match`, `if-range`, |
2534 | 2538 | `if-unmodified-since`, `last-modified`, `location`, `max-forwards`,
|
2535 | 2539 | `proxy-authorization`, `range`, `referer`,`retry-after`, `tk`,
|
2536 | 2540 | `upgrade-insecure-requests`, `user-agent` or `x-content-type-options` are
|
@@ -2908,8 +2912,9 @@ added: v8.4.0
|
2908 | 2912 |
|
2909 | 2913 | * {string}
|
2910 | 2914 |
|
2911 |
| -The request authority pseudo header field. It can also be accessed via |
2912 |
| -`req.headers[':authority']`. |
| 2915 | +The request authority pseudo header field. Because HTTP/2 allows requests |
| 2916 | +to set either `:authority` or `host`, this value is derived from |
| 2917 | +`req.headers[':authority']` if present, `req.headers['host']` otherwise. |
2913 | 2918 |
|
2914 | 2919 | #### `request.complete`
|
2915 | 2920 | <!-- YAML
|
@@ -3708,6 +3713,25 @@ following additional properties:
|
3708 | 3713 | * `type` {string} Either `'server'` or `'client'` to identify the type of
|
3709 | 3714 | `Http2Session`.
|
3710 | 3715 |
|
| 3716 | +## Note on `:authority` and `host` |
| 3717 | + |
| 3718 | +HTTP/2 requires requests to have either the `:authority` pseudo-header |
| 3719 | +or the `host` header. Using `:authority` should be preferred when |
| 3720 | +constructing an HTTP/2 request directly, and `host` should be |
| 3721 | +preferred when converting from HTTP/1 (in proxies, for instance). |
| 3722 | + |
| 3723 | +Historically, Node.js required all requests to have the `:authority` |
| 3724 | +pseudo-header and rejected with the `host` header present. |
| 3725 | +This has been corrected; the `host` header is now allowed, and the |
| 3726 | +only requirement is for either `host` or `:authority` to be |
| 3727 | +present (or both). The same validations from `:authority` extend |
| 3728 | +to `host`. |
| 3729 | + |
| 3730 | +The compatibility API falls back to `host` if `:authority` is not |
| 3731 | +present, see [`request.authority`][]. However, if you don't use the |
| 3732 | +compatibility API (or use `req.headers` directly), you need to |
| 3733 | +implement any fall-back behaviour yourself. |
| 3734 | + |
3711 | 3735 | [ALPN Protocol ID]: https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids
|
3712 | 3736 | [ALPN negotiation]: #http2_alpn_negotiation
|
3713 | 3737 | [Compatibility API]: #http2_compatibility_api
|
@@ -3748,6 +3772,7 @@ following additional properties:
|
3748 | 3772 | [`net.Socket.prototype.unref()`]: net.html#net_socket_unref
|
3749 | 3773 | [`net.Socket`]: net.html#net_class_net_socket
|
3750 | 3774 | [`net.connect()`]: net.html#net_net_connect
|
| 3775 | +[`request.authority`]: #http2_request_authority |
3751 | 3776 | [`request.socket`]: #http2_request_socket
|
3752 | 3777 | [`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed
|
3753 | 3778 | [`response.end()`]: #http2_response_end_data_encoding_callback
|
|
0 commit comments