Skip to content

Commit 1eda39e

Browse files
committed
backward compatibilty tests
1 parent d9c1200 commit 1eda39e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/internal/http2/core.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,8 +3259,10 @@ function connectionListener(socket) {
32593259
if (socket.alpnProtocol === false || socket.alpnProtocol === 'http/1.1') {
32603260
// Fallback to HTTP/1.1
32613261
if (options.allowHTTP1 === true) {
3262-
socket.server[kIncomingMessage] = options.Http1IncomingMessage;
3263-
socket.server[kServerResponse] = options.Http1ServerResponse;
3262+
socket.server[kIncomingMessage] =
3263+
options.http1Options.IncomingMessage || http.IncomingMessage;
3264+
socket.server[kServerResponse] =
3265+
options.http1Options.ServerResponse || http.ServerResponse;
32643266
return httpConnectionListener.call(this, socket);
32653267
}
32663268
// Let event handler deal with the socket
@@ -3342,9 +3344,18 @@ function initializeOptions(options) {
33423344
options.unknownProtocolTimeout = 10000;
33433345

33443346

3345-
// Used only with allowHTTP1
3346-
options.Http1IncomingMessage ||= http.IncomingMessage;
3347-
options.Http1ServerResponse ||= http.ServerResponse;
3347+
// Initialize http1Options bag for HTTP/1 fallback when allowHTTP1 is true.
3348+
// This bag is passed to storeHTTPOptions() to configure HTTP/1 server
3349+
// behavior (timeouts, IncomingMessage/ServerResponse classes, etc.).
3350+
options.http1Options = { ...options.http1Options };
3351+
3352+
// Backward compat: migrate deprecated top-level Http1 options (DEP0201)
3353+
if (options.Http1IncomingMessage !== undefined) {
3354+
options.http1Options.IncomingMessage ??= options.Http1IncomingMessage;
3355+
}
3356+
if (options.Http1ServerResponse !== undefined) {
3357+
options.http1Options.ServerResponse ??= options.Http1ServerResponse;
3358+
}
33483359

33493360
options.Http2ServerRequest ||= Http2ServerRequest;
33503361
options.Http2ServerResponse ||= Http2ServerResponse;
@@ -3392,7 +3403,7 @@ class Http2SecureServer extends TLSServer {
33923403
this.timeout = 0;
33933404
this.on('newListener', setupCompat);
33943405
if (options.allowHTTP1 === true) {
3395-
storeHTTPOptions.call(this, options);
3406+
storeHTTPOptions.call(this, { ...options, ...options.http1Options });
33963407
this.shouldUpgradeCallback = function() {
33973408
return this.listenerCount('upgrade') > 0;
33983409
};

0 commit comments

Comments
 (0)