diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index baeabb78505c1b..484a38119b9360 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -4517,6 +4517,20 @@ Type: Documentation-only Passing a non-extractable [`CryptoKey`][] to [`KeyObject.from()`][] is deprecated and will throw an error in a future version. +### DEP0205: `CRLF` constant from `_http_common` + + + +Type: Runtime + +The `CRLF` constant exported from the internal `_http_common` module is +deprecated. Use the string `'\r\n'` directly instead. + [DEP0142]: #dep0142-repl_builtinlibs [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 diff --git a/lib/_http_common.js b/lib/_http_common.js index 3c389ba054decc..0afe5650b24173 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -23,6 +23,7 @@ const { MathMin, + ObjectDefineProperty, Symbol, Uint8Array, } = primordials; @@ -300,12 +301,13 @@ function isLenient() { return insecureHTTPParser; } +let warnedCRLF = false; + module.exports = { _checkInvalidHeaderChar: checkInvalidHeaderChar, _checkIsHttpToken: checkIsHttpToken, chunkExpression: /(?:^|\W)chunked(?:$|\W)/i, continueExpression: /(?:^|\W)100-continue(?:$|\W)/i, - CRLF: '\r\n', // TODO: Deprecate this. freeParser, methods, parsers, @@ -315,3 +317,21 @@ module.exports = { prepareError, kSkipPendingData, }; + +ObjectDefineProperty(module.exports, 'CRLF', { + __proto__: null, + configurable: true, + enumerable: true, + get() { + if (!warnedCRLF) { + warnedCRLF = true; + process.emitWarning( + "The CRLF constant from '_http_common' is deprecated. " + + "Use '\\r\\n' directly instead.", + 'DeprecationWarning', + 'DEP0205', + ); + } + return '\r\n'; + }, +}); diff --git a/test/parallel/test-http-common-crlf-deprecation.js b/test/parallel/test-http-common-crlf-deprecation.js new file mode 100644 index 00000000000000..350cb203475074 --- /dev/null +++ b/test/parallel/test-http-common-crlf-deprecation.js @@ -0,0 +1,19 @@ +// Flags: --no-warnings +'use strict'; + +const common = require('../common'); +const assert = require('assert'); + +common.expectWarning( + 'DeprecationWarning', + "The CRLF constant from '_http_common' is deprecated. " + + "Use '\\r\\n' directly instead.", + 'DEP0205', +); + +const { CRLF } = require('_http_common'); + +assert.strictEqual(CRLF, '\r\n'); + +// Accessing CRLF again should not emit another warning +assert.strictEqual(CRLF, '\r\n');