Skip to content

Commit 1938023

Browse files
anonrigjoshthoward
authored andcommitted
put http and https modules behind compat flag (#4456)
1 parent 99dd682 commit 1938023

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

src/workerd/api/node/node.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ bool isNodeJsCompatEnabled(auto featureFlags) {
6767
return featureFlags.getNodeJsCompat() || featureFlags.getNodeJsCompatV2();
6868
}
6969

70-
bool isExperimentalNodeJsCompatModule(kj::StringPtr name);
70+
constexpr bool isExperimentalNodeJsCompatModule(kj::StringPtr name) {
71+
return name == "node:fs"_kj;
72+
}
73+
74+
constexpr bool isNodeHttpModule(kj::StringPtr name) {
75+
return name == "node:http"_kj || name == "node:_http_common"_kj ||
76+
name == "node:_http_outgoing"_kj || name == "node:_http_client"_kj ||
77+
name == "node:_http_incoming"_kj || name == "node:_http_agent"_kj || name == "node:https"_kj;
78+
}
7179

7280
template <class Registry>
7381
void registerNodeJsCompatModules(Registry& registry, auto featureFlags) {
@@ -85,7 +93,7 @@ void registerNodeJsCompatModules(Registry& registry, auto featureFlags) {
8593
bool nodeJsCompatEnabled = isNodeJsCompatEnabled(featureFlags);
8694

8795
registry.addBuiltinBundleFiltered(NODE_BUNDLE, [&](jsg::Module::Reader module) {
88-
// node:fs and node:http will be considered experimental until they are completed,
96+
// node:fs will be considered experimental until it's completed,
8997
// so unless the experimental flag is enabled, don't register them.
9098
if (isExperimentalNodeJsCompatModule(module.getName())) {
9199
return featureFlags.getWorkerdExperimental();
@@ -97,6 +105,12 @@ void registerNodeJsCompatModules(Registry& registry, auto featureFlags) {
97105
return module.getType() == jsg::ModuleType::INTERNAL;
98106
}
99107

108+
// We put node:http and node:https modules behind a compat flag
109+
// for securing backward compatibility.
110+
if (isNodeHttpModule(module.getName())) {
111+
return featureFlags.getEnableNodejsHttpModules();
112+
}
113+
100114
return true;
101115
});
102116

src/workerd/api/node/tests/http-agent-nodejs-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
88
(name = "worker", esModule = embed "http-agent-nodejs-test.js")
99
],
1010
compatibilityDate = "2025-01-15",
11-
compatibilityFlags = ["nodejs_compat", "experimental"],
11+
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
1212
bindings = [
1313
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
1414
],

src/workerd/api/node/tests/http-client-nodejs-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
88
(name = "worker", esModule = embed "http-client-nodejs-test.js")
99
],
1010
compatibilityDate = "2025-01-15",
11-
compatibilityFlags = ["nodejs_compat", "experimental"],
11+
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
1212
bindings = [
1313
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
1414
(name = "ASD_SERVER_PORT", fromEnvironment = "ASD_SERVER_PORT"),

src/workerd/api/node/tests/http-nodejs-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
88
(name = "worker", esModule = embed "http-nodejs-test.js")
99
],
1010
compatibilityDate = "2025-01-15",
11-
compatibilityFlags = ["nodejs_compat", "experimental"],
11+
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
1212
bindings = [
1313
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
1414
(name = "ASD_SERVER_PORT", fromEnvironment = "ASD_SERVER_PORT"),

src/workerd/api/node/tests/http-outgoing-nodejs-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
88
(name = "worker", esModule = embed "http-outgoing-nodejs-test.js")
99
],
1010
compatibilityDate = "2025-01-15",
11-
compatibilityFlags = ["nodejs_compat", "experimental"],
11+
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
1212
bindings = [
1313
(name = "FINISH_WRITABLE_PORT", fromEnvironment = "FINISH_WRITABLE_PORT"),
1414
(name = "WRITABLE_FINISHED_PORT", fromEnvironment = "WRITABLE_FINISHED_PORT"),

src/workerd/api/node/util.c++

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212

1313
namespace workerd::api::node {
1414

15-
bool isExperimentalNodeJsCompatModule(kj::StringPtr name) {
16-
return name == "node:fs"_kj || name == "node:http"_kj || name == "node:_http_common"_kj ||
17-
name == "node:_http_outgoing"_kj || name == "node:_http_client"_kj ||
18-
name == "node:_http_incoming"_kj || name == "node:_http_agent"_kj;
19-
}
20-
2115
MIMEParams::MIMEParams(kj::Maybe<MimeType&> mimeType): mimeType(mimeType) {}
2216

2317
// Oddly, Node.js allows creating MIMEParams directly but it's not actually

src/workerd/io/compatibility-date.capnp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,4 +870,10 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
870870
# The original version of the headers sent to edgeworker were truncated to a single
871871
# value for specific header names, such as To and Cc. With this compat flag we will send
872872
# the full header values to the worker script.
873+
874+
enableNodejsHttpModules @100 :Bool
875+
$compatEnableFlag("enable_nodejs_http_modules")
876+
$compatDisableFlag("disable_nodejs_http_modules")
877+
$impliedByAfterDate(name = "nodeJsCompat", date = "2025-08-15");
878+
# Enables Node.js http related modules such as node:http and node:https
873879
}

0 commit comments

Comments
 (0)