From e989acc7f1b6b678aedc278ad5fd5a114b12055d Mon Sep 17 00:00:00 2001 From: "Shuowang (Wayne) Zhang" Date: Tue, 11 Feb 2020 17:14:22 -0500 Subject: [PATCH] http: make --insecure-http-parser configurable per-stream or per-server Backport 7fc5656 Original commit message: From the issue: > Some servers deviate from HTTP spec enougth that Node.js can't > communicate with them, but "work" when `--insecure-http-parser` > is enabled globally. It would be useful to be able to use this > mode, as a client, only when connecting to known bad servers. This is largely equivalent to https://github.com/nodejs/node/pull/31446 in terms of code changes. Fixes: https://github.com/nodejs/node/issues/31440 Refs: https://github.com/nodejs/node/pull/31446 Backport-PR-URL: https://github.com/nodejs/node/pull/31500 PR-URL: https://github.com/nodejs/node/pull/31448 Reviewed-By: Sam Roberts Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Rich Trott --- doc/api/http.md | 33 +++++++- lib/_http_client.js | 11 ++- lib/_http_server.js | 13 ++- lib/http.js | 4 +- .../test-http-insecure-parser-per-stream.js | 82 +++++++++++++++++++ 5 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 test/parallel/test-http-insecure-parser-per-stream.js diff --git a/doc/api/http.md b/doc/api/http.md index 8af25b4e02ef..5326ca180bb3 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1721,11 +1721,30 @@ A collection of all the standard HTTP response status codes, and the short description of each. For example, `http.STATUS_CODES[404] === 'Not Found'`. -## http.createServer([requestListener]) +## http.createServer([options][, requestListener]) -- `requestListener` {Function} +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/31448 + description: The `insecureHTTPParser` option is supported now. + - version: v9.6.0, v8.12.0 + pr-url: https://github.com/nodejs/node/pull/15752 + description: The `options` argument is supported now. +--> + +* `options` {Object} + * `IncomingMessage` {http.IncomingMessage} Specifies the `IncomingMessage` + class to be used. Useful for extending the original `IncomingMessage`. + **Default:** `IncomingMessage`. + * `ServerResponse` {http.ServerResponse} Specifies the `ServerResponse` class + to be used. Useful for extending the original `ServerResponse`. **Default:** + `ServerResponse`. + * `insecureHTTPParser` {boolean} Use an insecure HTTP parser that accepts + invalid HTTP headers when `true`. Using the insecure parser should be + avoided. See [`--insecure-http-parser`][] for more information. + **Default:** `false` +* `requestListener` {Function} * Returns: {http.Server} @@ -1820,6 +1839,9 @@ Defaults to 8KB. Configurable using the [`--max-http-header-size`][] CLI option.