Commit 8002dbdc27b for nodejs

commit 8002dbdc27bb844501320844e4c74944d24c6ece
Author: James M Snell <jasnell@gmail.com>
Date:   Sun Nov 15 17:36:15 2026 +0000

    http: share insecureHTTPParser/httpValidation option handling

    ClientRequest and Server duplicated the validation of the
    insecureHTTPParser and httpValidation options, including the check
    that they are mutually exclusive. Move it into a shared
    setHttpParserOptions() helper in internal/http.

    Assisted-by: Claude
    Signed-off-by: James M Snell <jasnell@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67495
    Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
    Reviewed-By: Filip Skokan <panva.ip@gmail.com>
    Reviewed-By: Robert Nagy <ronagy@icloud.com>
    Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>

diff --git a/lib/internal/http.js b/lib/internal/http.js
index 68d4a75a253..1fa8bf24d82 100644
--- a/lib/internal/http.js
+++ b/lib/internal/http.js
@@ -20,7 +20,11 @@ const {
 const { URL } = require('internal/url');
 const { Buffer } = require('buffer');
 const { isIPv4 } = require('internal/net');
-const { ERR_PROXY_INVALID_CONFIG } = require('internal/errors').codes;
+const {
+  ERR_INVALID_ARG_VALUE,
+  ERR_PROXY_INVALID_CONFIG,
+} = require('internal/errors').codes;
+const { validateBoolean, validateOneOf } = require('internal/validators');
 let utcCache;
 let utcHeaderCache;

@@ -301,6 +305,33 @@ function getGlobalAgent(proxyEnv, Agent) {
   });
 }

+/**
+ * Validates the `insecureHTTPParser` and `httpValidation` options shared by
+ * HTTP clients and servers, and sets them on `target`.
+ * @param {object} target
+ * @param {{ insecureHTTPParser?: boolean, httpValidation?: string }} options
+ */
+function setHttpParserOptions(target, options) {
+  const insecureHTTPParser = options.insecureHTTPParser;
+  if (insecureHTTPParser !== undefined)
+    validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
+  target.insecureHTTPParser = insecureHTTPParser;
+
+  const httpValidation = options.httpValidation;
+  if (httpValidation !== undefined) {
+    validateOneOf(httpValidation, 'options.httpValidation',
+                  ['strict', 'relaxed', 'insecure']);
+    if (insecureHTTPParser !== undefined) {
+      throw new ERR_INVALID_ARG_VALUE(
+        'options.httpValidation',
+        httpValidation,
+        'cannot be used together with options.insecureHTTPParser',
+      );
+    }
+  }
+  target.httpValidation = httpValidation;
+}
+
 module.exports = {
   kOutHeaders: Symbol('kOutHeaders'),
   kNeedDrain: Symbol('kNeedDrain'),
@@ -318,4 +349,5 @@ module.exports = {
   getGlobalAgent,
   parseProxyUrl,
   redactProxyUrl,
+  setHttpParserOptions,
 };
diff --git a/lib/internal/http/client.js b/lib/internal/http/client.js
index ecc87255311..880e0ee5240 100644
--- a/lib/internal/http/client.js
+++ b/lib/internal/http/client.js
@@ -72,6 +72,7 @@ const {
   getNextTraceEventId,
   kProxyConfig,
   checkShouldUseProxy,
+  setHttpParserOptions,
 } = require('internal/http');
 const {
   ConnResetException,
@@ -87,7 +88,6 @@ const {
 const {
   validateInteger,
   validateBoolean,
-  validateOneOf,
   validatePort,
   validateString,
 } = require('internal/validators');
@@ -456,27 +456,7 @@ function ClientRequest(input, options, cb) {
     validateInteger(maxHeaderSize, 'maxHeaderSize', 0);
   this.maxHeaderSize = maxHeaderSize;

-  const insecureHTTPParser = options.insecureHTTPParser;
-  if (insecureHTTPParser !== undefined) {
-    validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
-  }
-
-  this.insecureHTTPParser = insecureHTTPParser;
-
-  const httpValidation = options.httpValidation;
-  if (httpValidation !== undefined) {
-    validateOneOf(httpValidation, 'options.httpValidation',
-                  ['strict', 'relaxed', 'insecure']);
-    if (insecureHTTPParser !== undefined) {
-      throw new ERR_INVALID_ARG_VALUE(
-        'options.httpValidation',
-        httpValidation,
-        'cannot be used together with options.insecureHTTPParser',
-      );
-    }
-  }
-
-  this.httpValidation = httpValidation;
+  setHttpParserOptions(this, options);

   if (options.joinDuplicateHeaders !== undefined) {
     validateBoolean(options.joinDuplicateHeaders, 'options.joinDuplicateHeaders');
diff --git a/lib/internal/http/server.js b/lib/internal/http/server.js
index 9e13aeba63a..fe870c47144 100644
--- a/lib/internal/http/server.js
+++ b/lib/internal/http/server.js
@@ -65,6 +65,7 @@ const {
   traceBegin,
   traceEnd,
   getNextTraceEventId,
+  setHttpParserOptions,
 } = require('internal/http');
 const {
   defaultTriggerAsyncIdScope,
@@ -99,7 +100,6 @@ const {
 const {
   validateInteger,
   validateBoolean,
-  validateOneOf,
   validateLinkHeaderValue,
   validateObject,
   validateFunction,
@@ -538,24 +538,7 @@ function storeHTTPOptions(options) {
     validateBoolean(optimizeEmptyRequests, 'options.optimizeEmptyRequests');
   this[kOptimizeEmptyRequests] = optimizeEmptyRequests || false;

-  const insecureHTTPParser = options.insecureHTTPParser;
-  if (insecureHTTPParser !== undefined)
-    validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
-  this.insecureHTTPParser = insecureHTTPParser;
-
-  const httpValidation = options.httpValidation;
-  if (httpValidation !== undefined) {
-    validateOneOf(httpValidation, 'options.httpValidation',
-                  ['strict', 'relaxed', 'insecure']);
-    if (insecureHTTPParser !== undefined) {
-      throw new ERR_INVALID_ARG_VALUE(
-        'options.httpValidation',
-        httpValidation,
-        'cannot be used together with options.insecureHTTPParser',
-      );
-    }
-  }
-  this.httpValidation = httpValidation;
+  setHttpParserOptions(this, options);

   const requestTimeout = options.requestTimeout;
   if (requestTimeout !== undefined) {