Commit f5c0e28
committed
http2: allow Host in HTTP/2 requests
The HTTP/2 spec allows Host to be used instead of :authority in
requests, and this is in fact *preferred* when converting from HTTP/1.
We erroneously treated Host as a connection header, thus disallowing
it in requests. The patch corrects this, aligning Node.js behaviour
with the HTTP/2 spec and with nghttp2:
- Treat Host as a single-value header instead of a connection header.
- Don't autofill :authority if Host is present.
- The compatibility API (request.authority) falls back to using Host
if :authority is not present.
This is semver-major because requests are no longer guaranteed to
have :authority set. An explanatory note was added to the docs.
Fixes: #29858
PR-URL: #34664
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>1 parent 42a3a7f commit f5c0e28Copy full SHA for f5c0e28
File tree
Expand file treeCollapse file tree
6 files changed
+125
-14
lines changedOpen diff view settings
Filter options
- doc/api
- lib/internal/http2
- test/parallel
Expand file treeCollapse file tree
6 files changed
+125
-14
lines changedOpen diff view settings
Collapse file
+22-3Lines changed: 22 additions & 3 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
2 | 2 | |
3 | 3 | |
4 | 4 | |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
5 | 9 | |
6 | 10 | |
7 | 11 | |
| ||
2530 | 2534 | |
2531 | 2535 | |
2532 | 2536 | |
2533 | | - |
| 2537 | + |
2534 | 2538 | |
2535 | 2539 | |
2536 | 2540 | |
| ||
2909 | 2913 | |
2910 | 2914 | |
2911 | 2915 | |
2912 | | - |
2913 | | - |
| 2916 | + |
| 2917 | + |
| 2918 | + |
| 2919 | + |
2914 | 2920 | |
2915 | 2921 | |
2916 | 2922 | |
| ||
3709 | 3715 | |
3710 | 3716 | |
3711 | 3717 | |
| 3718 | + |
| 3719 | + |
| 3720 | + |
| 3721 | + |
| 3722 | + |
| 3723 | + |
| 3724 | + |
| 3725 | + |
| 3726 | + |
| 3727 | + |
| 3728 | + |
| 3729 | + |
3712 | 3730 | |
3713 | 3731 | |
3714 | 3732 | |
| ||
3749 | 3767 | |
3750 | 3768 | |
3751 | 3769 | |
| 3770 | + |
3752 | 3771 | |
3753 | 3772 | |
3754 | 3773 | |
|
Collapse file
lib/internal/http2/compat.js
Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js+3-2Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | | - |
| 53 | + |
| 54 | + |
54 | 55 | |
55 | 56 | |
56 | 57 | |
| ||
395 | 396 | |
396 | 397 | |
397 | 398 | |
398 | | - |
| 399 | + |
399 | 400 | |
400 | 401 | |
401 | 402 | |
|
Collapse file
+5-4Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
118 | 118 | |
119 | 119 | |
120 | 120 | |
| 121 | + |
121 | 122 | |
122 | 123 | |
123 | 124 | |
| ||
1636 | 1637 | |
1637 | 1638 | |
1638 | 1639 | |
1639 | | - |
| 1640 | + |
1640 | 1641 | |
1641 | 1642 | |
1642 | 1643 | |
| ||
1667 | 1668 | |
1668 | 1669 | |
1669 | 1670 | |
1670 | | - |
| 1671 | + |
1671 | 1672 | |
1672 | 1673 | |
1673 | 1674 | |
| ||
2459 | 2460 | |
2460 | 2461 | |
2461 | 2462 | |
2462 | | - |
| 2463 | + |
2463 | 2464 | |
2464 | 2465 | |
2465 | 2466 | |
| ||
2502 | 2503 | |
2503 | 2504 | |
2504 | 2505 | |
2505 | | - |
| 2506 | + |
2506 | 2507 | |
2507 | 2508 | |
2508 | 2509 | |
|
Collapse file
+14-2Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
61 | 61 | |
62 | 62 | |
63 | 63 | |
| 64 | + |
64 | 65 | |
65 | 66 | |
66 | 67 | |
| ||
84 | 85 | |
85 | 86 | |
86 | 87 | |
87 | | - |
88 | 88 | |
89 | 89 | |
90 | 90 | |
| ||
131 | 131 | |
132 | 132 | |
133 | 133 | |
| 134 | + |
134 | 135 | |
135 | 136 | |
136 | 137 | |
| ||
429 | 430 | |
430 | 431 | |
431 | 432 | |
432 | | - |
433 | 433 | |
434 | 434 | |
435 | 435 | |
| ||
625 | 625 | |
626 | 626 | |
627 | 627 | |
| 628 | + |
| 629 | + |
| 630 | + |
| 631 | + |
| 632 | + |
| 633 | + |
| 634 | + |
| 635 | + |
| 636 | + |
| 637 | + |
| 638 | + |
628 | 639 | |
629 | 640 | |
630 | 641 | |
631 | 642 | |
632 | 643 | |
633 | 644 | |
| 645 | + |
634 | 646 | |
635 | 647 | |
636 | 648 | |
|
Collapse file
test/parallel/test-http2-compat-serverrequest-host.js
Copy file name to clipboard+63Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
Collapse file
test/parallel/test-http2-util-headers-list.js
Copy file name to clipboardExpand all lines: test/parallel/test-http2-util-headers-list.js+18-3Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
8 | 8 | |
9 | 9 | |
10 | 10 | |
11 | | - |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
12 | 16 | |
13 | 17 | |
14 | 18 | |
| ||
34 | 38 | |
35 | 39 | |
36 | 40 | |
| 41 | + |
37 | 42 | |
38 | 43 | |
39 | 44 | |
| ||
86 | 91 | |
87 | 92 | |
88 | 93 | |
89 | | - |
90 | 94 | |
91 | 95 | |
92 | 96 | |
| ||
225 | 229 | |
226 | 230 | |
227 | 231 | |
| 232 | + |
228 | 233 | |
229 | 234 | |
230 | 235 | |
| ||
289 | 294 | |
290 | 295 | |
291 | 296 | |
292 | | - |
293 | 297 | |
294 | 298 | |
295 | 299 | |
| ||
327 | 331 | |
328 | 332 | |
329 | 333 | |
| 334 | + |
| 335 | + |
| 336 | + |
| 337 | + |
| 338 | + |
| 339 | + |
| 340 | + |
| 341 | + |
| 342 | + |
| 343 | + |
| 344 | + |
330 | 345 | |
331 | 346 | |
332 | 347 | |
|
0 commit comments