From a0b610450a95d2111fbd2053dc9a4c840d618ac1 Mon Sep 17 00:00:00 2001 From: Beth Griggs Date: Thu, 4 Mar 2021 17:17:47 +0000 Subject: [PATCH] http: runtime deprecate legacy HTTP parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The legacy HTTP parser, used by default in versions of Node.js prior to 12.0.0, is deprecated. The legacy HTTP parser cannot be guaranteed to be supported after April 2021. This commit introduces a deprecation warning for the legacy HTTP parser. PR-URL: https://github.com/nodejs/node/pull/37603 Refs: https://github.com/nodejs/node/issues/31441 Reviewed-By: Richard Lau Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Michaƫl Zasso --- doc/api/cli.md | 6 ++++++ doc/api/deprecations.md | 5 ++++- src/node_http_parser_impl.h | 7 +++++++ test/parallel/test-http-parser-legacy-deprecation.js | 11 +++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http-parser-legacy-deprecation.js diff --git a/doc/api/cli.md b/doc/api/cli.md index e6d49feef624c0..d36cc5100bc7cf 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -383,6 +383,10 @@ Specify the file name of the heap profile generated by `--heap-prof`. ### `--http-parser=library` Chooses an HTTP parser library. Available values are: @@ -392,6 +396,8 @@ Chooses an HTTP parser library. Available values are: The default is `llhttp`, unless otherwise specified when building Node.js. +The `legacy` HTTP parser is deprecated and will emit a deprecation warning. + 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. diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 8333597513a756..95a452db3d92a3 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2469,12 +2469,15 @@ Module.createRequireFromPath() is deprecated. Please use [`module.createRequire( ### DEP0131: Legacy HTTP parser -Type: Documentation-only +Type: Runtime The legacy HTTP parser, used by default in versions of Node.js prior to 12.0.0, is deprecated. This deprecation applies to users of the diff --git a/src/node_http_parser_impl.h b/src/node_http_parser_impl.h index 7c39bc15c72a38..77d09a939cb72b 100644 --- a/src/node_http_parser_impl.h +++ b/src/node_http_parser_impl.h @@ -26,6 +26,9 @@ #include "node.h" #include "node_buffer.h" +#ifndef NODE_EXPERIMENTAL_HTTP +#include "node_process.h" +#endif /* NODE_EXPERIMENTAL_HTTP */ #include "util.h" #include "async_wrap-inl.h" @@ -1021,6 +1024,10 @@ void InitializeHttpParser(Local target, #ifndef NODE_EXPERIMENTAL_HTTP static uv_once_t init_once = UV_ONCE_INIT; uv_once(&init_once, InitMaxHttpHeaderSizeOnce); + ProcessEmitDeprecationWarning( + env, + "The legacy HTTP parser is deprecated.", + "DEP0131").IsNothing(); #endif /* NODE_EXPERIMENTAL_HTTP */ } diff --git a/test/parallel/test-http-parser-legacy-deprecation.js b/test/parallel/test-http-parser-legacy-deprecation.js new file mode 100644 index 00000000000000..6c4c690a9b9169 --- /dev/null +++ b/test/parallel/test-http-parser-legacy-deprecation.js @@ -0,0 +1,11 @@ +'use strict'; +const common = require('../common'); + +// Flags: --http-parser=legacy +require('http'); + +common.expectWarning({ + DeprecationWarning: + ['The legacy HTTP parser is deprecated.', + 'DEP0131'] +});