From 50b3ce86305cf3655d5956c4896efcf8c2713671 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 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. --- doc/api/deprecations.md | 5 ++++- src/node_http_parser_impl.h | 7 +++++++ test/parallel/test-http-parser-legacy-deprecation.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http-parser-legacy-deprecation.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 8333597513a756..82226d4fbe4772 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'] +});