GeezerVison is showing github.com — http: make parser choice a runtime flag · nodejs/node@c8d5e31
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: configure.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 187 | 187 | parser.add_option('--experimental-http-parser', | 188 | 188 | action='store_true', | 189 | 189 | dest='experimental_http_parser', | 190 | | - help='use llhttp instead of http_parser') | | 190 | + help='use llhttp instead of http_parser by default') | 191 | 191 |
| 192 | 192 | shared_optgroup.add_option('--shared-http-parser', | 193 | 193 | action='store_true', | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +16Lines changed: 16 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -119,6 +119,22 @@ added: v6.0.0 | 119 | 119 | Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.) | 120 | 120 | (Same requirements as `--enable-fips`.) | 121 | 121 |
| | 122 | +### `--http-parser=library` | | 123 | +<!-- YAML | | 124 | +added: REPLACEME | | 125 | +--> | | 126 | + | | 127 | +Chooses an HTTP parser library. Available values are: | | 128 | + | | 129 | +- `llhttp` for https://llhttp.org/ | | 130 | +- `legacy` for https://github.com/nodejs/http-parser | | 131 | + | | 132 | +The default is `legacy`, unless otherwise specified when building Node.js. | | 133 | + | | 134 | +This flag exists to aid in experimentation with the internal implementation of | | 135 | +the Node.js http parser. | | 136 | +This flag is likely to become a no-op and removed at some point in the future. | | 137 | + | 122 | 138 | ### `--icu-data-dir=file` | 123 | 139 | <!-- YAML | 124 | 140 | added: v0.11.15 | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,6 +97,12 @@ Enable experimental ES module support in VM module. | 97 | 97 | .It Fl -experimental-worker | 98 | 98 | Enable experimental worker threads using worker_threads module. | 99 | 99 | . | | 100 | +.It Fl -http-parser Ns = Ns Ar library | | 101 | +Chooses an HTTP parser library. Available values are | | 102 | +.Sy llhttp | | 103 | +or | | 104 | +.Sy legacy . | | 105 | +. | 100 | 106 | .It Fl -force-fips | 101 | 107 | Force FIPS-compliant crypto on startup | 102 | 108 | (Cannot be disabled from script code). | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_client.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | const util = require('util'); | 25 | 25 | const net = require('net'); | 26 | 26 | const url = require('url'); | 27 | | -const { HTTPParser } = internalBinding('http_parser'); | 28 | 27 | const assert = require('assert').ok; | 29 | 28 | const { | 30 | 29 | _checkIsHttpToken: checkIsHttpToken, | 31 | 30 | debug, | 32 | 31 | freeParser, | 33 | 32 | httpSocketSetup, | 34 | | - parsers | | 33 | + parsers, | | 34 | + HTTPParser, | 35 | 35 | } = require('_http_common'); | 36 | 36 | const { OutgoingMessage } = require('_http_outgoing'); | 37 | 37 | const Agent = require('_http_agent'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_common.js +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 |
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | | -const { methods, HTTPParser } = internalBinding('http_parser'); | | 24 | +const { getOptionValue } = require('internal/options'); | | 25 | + | | 26 | +const { methods, HTTPParser } = | | 27 | + getOptionValue('--http-parser') === 'legacy' ? | | 28 | + internalBinding('http_parser') : internalBinding('http_parser_llhttp'); | 25 | 29 |
| 26 | 30 | const { FreeList } = require('internal/freelist'); | 27 | 31 | const { ondrain } = require('internal/http'); | @@ -243,5 +247,6 @@ module.exports = { | 243 | 247 | httpSocketSetup, | 244 | 248 | methods, | 245 | 249 | parsers, | 246 | | - kIncomingMessage | | 250 | + kIncomingMessage, | | 251 | + HTTPParser | 247 | 252 | }; |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_server.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 |
| 24 | 24 | const util = require('util'); | 25 | 25 | const net = require('net'); | 26 | | -const { HTTPParser } = internalBinding('http_parser'); | 27 | 26 | const assert = require('assert').ok; | 28 | 27 | const { | 29 | 28 | parsers, | @@ -34,6 +33,7 @@ const { | 34 | 33 | chunkExpression, | 35 | 34 | httpSocketSetup, | 36 | 35 | kIncomingMessage, | | 36 | + HTTPParser, | 37 | 37 | _checkInvalidHeaderChar: checkInvalidHeaderChar | 38 | 38 | } = require('_http_common'); | 39 | 39 | const { OutgoingMessage } = require('_http_outgoing'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/child_process.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -127,7 +127,7 @@ const handleConversion = { | 127 | 127 | if (freeParser === undefined) | 128 | 128 | freeParser = require('_http_common').freeParser; | 129 | 129 | if (HTTPParser === undefined) | 130 | | - HTTPParser = internalBinding('http_parser').HTTPParser; | | 130 | + HTTPParser = require('_http_common').HTTPParser; | 131 | 131 |
| 132 | 132 | // In case of an HTTP connection socket, release the associated | 133 | 133 | // resources | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 352 | 352 | 'src/node_encoding.cc', | 353 | 353 | 'src/node_errors.cc', | 354 | 354 | 'src/node_file.cc', | 355 | | - 'src/node_http_parser.cc', | | 355 | + 'src/node_http_parser_llhttp.cc', | | 356 | + 'src/node_http_parser_traditional.cc', | 356 | 357 | 'src/node_http2.cc', | 357 | 358 | 'src/node_i18n.cc', | 358 | 359 | 'src/node_messaging.cc', | | 423 | 424 | 'src/node_contextify.h', | 424 | 425 | 'src/node_errors.h', | 425 | 426 | 'src/node_file.h', | | 427 | + 'src/node_http_parser_impl.h', | 426 | 428 | 'src/node_http2.h', | 427 | 429 | 'src/node_http2_state.h', | 428 | 430 | 'src/node_i18n.h', | |
Collapse file Copy file name to clipboardExpand all lines: node.gypi +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 164 | 164 | }], | 165 | 165 |
| 166 | 166 | [ 'node_experimental_http_parser=="true"', { | 167 | | - 'defines': [ 'NODE_EXPERIMENTAL_HTTP' ], | 168 | | - 'dependencies': [ 'deps/llhttp/llhttp.gyp:llhttp' ], | 169 | | - }, { | 170 | | - 'conditions': [ [ 'node_shared_http_parser=="false"', { | 171 | | - 'dependencies': [ 'deps/http_parser/http_parser.gyp:http_parser' ], | 172 | | - } ] ], | | 167 | + 'defines': [ 'NODE_EXPERIMENTAL_HTTP_DEFAULT' ], | | 168 | + } ], | | 169 | + | | 170 | + [ 'node_shared_http_parser=="false"', { | | 171 | + 'dependencies': [ | | 172 | + 'deps/http_parser/http_parser.gyp:http_parser', | | 173 | + 'deps/llhttp/llhttp.gyp:llhttp' | | 174 | + ], | 173 | 175 | } ], | 174 | 176 |
| 175 | 177 | [ 'node_shared_cares=="false"', { | |
Collapse file Copy file name to clipboardExpand all lines: src/inspector_socket.cc +10-6Lines changed: 10 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #include "inspector_socket.h" | 2 | 2 |
| | 3 | +#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT | | 4 | +#define NODE_EXPERIMENTAL_HTTP | | 5 | +#endif | 3 | 6 | #include "http_parser_adaptor.h" | | 7 | + | 4 | 8 | #include "util-inl.h" | 5 | 9 |
| 6 | 10 | #define NODE_WANT_INTERNALS 1 | @@ -433,13 +437,13 @@ class HttpHandler : public ProtocolHandler { | 433 | 437 | explicit HttpHandler(InspectorSocket* inspector, TcpHolder::Pointer tcp) | 434 | 438 | : ProtocolHandler(inspector, std::move(tcp)), | 435 | 439 | parsing_value_(false) { | 436 | | -#ifdef NODE_EXPERIMENTAL_HTTP | | 440 | +#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT | 437 | 441 | llhttp_init(&parser_, HTTP_REQUEST, &parser_settings); | 438 | 442 | llhttp_settings_init(&parser_settings); | 439 | | -#else /* !NODE_EXPERIMENTAL_HTTP */ | | 443 | +#else /* !NODE_EXPERIMENTAL_HTTP_DEFAULT */ | 440 | 444 | http_parser_init(&parser_, HTTP_REQUEST); | 441 | 445 | http_parser_settings_init(&parser_settings); | 442 | | -#endif /* NODE_EXPERIMENTAL_HTTP */ | | 446 | +#endif /* NODE_EXPERIMENTAL_HTTP_DEFAULT */ | 443 | 447 | parser_settings.on_header_field = OnHeaderField; | 444 | 448 | parser_settings.on_header_value = OnHeaderValue; | 445 | 449 | parser_settings.on_message_complete = OnMessageComplete; | @@ -484,17 +488,17 @@ class HttpHandler : public ProtocolHandler { | 484 | 488 |
| 485 | 489 | void OnData(std::vector<char>* data) override { | 486 | 490 | parser_errno_t err; | 487 | | -#ifdef NODE_EXPERIMENTAL_HTTP | | 491 | +#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT | 488 | 492 | err = llhttp_execute(&parser_, data->data(), data->size()); | 489 | 493 |
| 490 | 494 | if (err == HPE_PAUSED_UPGRADE) { | 491 | 495 | err = HPE_OK; | 492 | 496 | llhttp_resume_after_upgrade(&parser_); | 493 | 497 | } | 494 | | -#else /* !NODE_EXPERIMENTAL_HTTP */ | | 498 | +#else /* !NODE_EXPERIMENTAL_HTTP_DEFAULT */ | 495 | 499 | http_parser_execute(&parser_, &parser_settings, data->data(), data->size()); | 496 | 500 | err = HTTP_PARSER_ERRNO(&parser_); | 497 | | -#endif /* NODE_EXPERIMENTAL_HTTP */ | | 501 | +#endif /* NODE_EXPERIMENTAL_HTTP_DEFAULT */ | 498 | 502 | data->clear(); | 499 | 503 | if (err != HPE_OK) { | 500 | 504 | CancelHandshake(); | |
|