@@ -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
7280template <class Registry >
7381void 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
0 commit comments