From dd4887914467e90732cb48a69bce881a89e1f4c0 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 30 Nov 2018 07:39:02 +0100 Subject: [PATCH] http: make parser choice a runtime flag Add a `--http-parser=llhttp` vs `--http-parser=traditional` command line switch, to make testing and comparing the new llhttp-based implementation easier. PR-URL: https://github.com/nodejs/node/pull/24739 Refs: https://github.com/nodejs/node/issues/24730 Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: Fedor Indutny Reviewed-By: Gus Caplan Reviewed-By: Matheus Marchini Reviewed-By: Matteo Collina Reviewed-By: Ali Ijaz Sheikh --- configure.py | 2 +- doc/api/cli.md | 16 ++++++++++++++++ doc/node.1 | 6 ++++++ lib/_http_client.js | 4 ++-- lib/_http_common.js | 9 +++++++-- lib/_http_server.js | 2 +- lib/internal/child_process.js | 2 +- node.gyp | 4 +++- node.gypi | 14 ++++++++------ src/inspector_socket.cc | 16 ++++++++++------ src/node_binding.cc | 1 + ..._http_parser.cc => node_http_parser_impl.h} | 18 ++++++++++++------ src/node_http_parser_llhttp.cc | 17 +++++++++++++++++ src/node_http_parser_traditional.cc | 18 ++++++++++++++++++ src/node_internals.h | 3 +++ src/node_metadata.cc | 16 ++-------------- src/node_metadata.h | 11 +++-------- src/node_options.cc | 14 ++++++++++++++ src/node_options.h | 6 ++++++ test/async-hooks/test-httpparser.request.js | 8 +------- test/async-hooks/test-httpparser.response.js | 8 +------- test/parallel/test-http-parser-bad-ref.js | 5 ++--- test/parallel/test-http-parser-lazy-loaded.js | 7 ++++++- test/parallel/test-http-parser.js | 5 +---- test/parallel/test-process-versions.js | 10 ++++------ test/parallel/test-trace-events-metadata.js | 7 ++++--- test/sequential/test-async-wrap-getasyncid.js | 2 +- test/sequential/test-http-max-http-headers.js | 8 +++++--- test/sequential/test-http-regr-gh-2928.js | 3 +-- 29 files changed, 157 insertions(+), 85 deletions(-) rename src/{node_http_parser.cc => node_http_parser_impl.h} (98%) create mode 100644 src/node_http_parser_llhttp.cc create mode 100644 src/node_http_parser_traditional.cc diff --git a/configure.py b/configure.py index 3d4cea32cdefb1..1bef01baef5fbc 100755 --- a/configure.py +++ b/configure.py @@ -187,7 +187,7 @@ parser.add_option('--experimental-http-parser', action='store_true', dest='experimental_http_parser', - help='use llhttp instead of http_parser') + help='use llhttp instead of http_parser by default') shared_optgroup.add_option('--shared-http-parser', action='store_true', diff --git a/doc/api/cli.md b/doc/api/cli.md index 66ee946c322281..aa4d28c9fe1d8c 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -119,6 +119,22 @@ added: v6.0.0 Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.) (Same requirements as `--enable-fips`.) +### `--http-parser=library` + + +Chooses an HTTP parser library. Available values are: + +- `llhttp` for https://llhttp.org/ +- `legacy` for https://github.com/nodejs/http-parser + +The default is `legacy`, unless otherwise specified when building Node.js. + +This flag exists to aid in experimentation with the internal implementation of +the Node.js http parser. +This flag is likely to become a no-op and removed at some point in the future. + ### `--icu-data-dir=file`