Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/workerd/api/node/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ bool isNodeJsCompatEnabled(auto featureFlags) {
return featureFlags.getNodeJsCompat() || featureFlags.getNodeJsCompatV2();
}

bool isExperimentalNodeJsCompatModule(kj::StringPtr name);
constexpr bool isExperimentalNodeJsCompatModule(kj::StringPtr name) {
return name == "node:fs"_kj;
}

constexpr bool isNodeHttpModule(kj::StringPtr name) {
return name == "node:http"_kj || name == "node:_http_common"_kj ||
name == "node:_http_outgoing"_kj || name == "node:_http_client"_kj ||
name == "node:_http_incoming"_kj || name == "node:_http_agent"_kj || name == "node:https"_kj;
}

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

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

// We put node:http and node:https modules behind a compat flag
// for securing backward compatibility.
if (isNodeHttpModule(module.getName())) {
return featureFlags.getEnableNodejsHttpModules();
}

return true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker", esModule = embed "http-agent-nodejs-test.js")
],
compatibilityDate = "2025-01-15",
compatibilityFlags = ["nodejs_compat", "experimental"],
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
bindings = [
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker", esModule = embed "http-client-nodejs-test.js")
],
compatibilityDate = "2025-01-15",
compatibilityFlags = ["nodejs_compat", "experimental"],
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
bindings = [
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
(name = "ASD_SERVER_PORT", fromEnvironment = "ASD_SERVER_PORT"),
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/node/tests/http-nodejs-test.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker", esModule = embed "http-nodejs-test.js")
],
compatibilityDate = "2025-01-15",
compatibilityFlags = ["nodejs_compat", "experimental"],
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
bindings = [
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
(name = "ASD_SERVER_PORT", fromEnvironment = "ASD_SERVER_PORT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker", esModule = embed "http-outgoing-nodejs-test.js")
],
compatibilityDate = "2025-01-15",
compatibilityFlags = ["nodejs_compat", "experimental"],
compatibilityFlags = ["nodejs_compat", "experimental", "enable_nodejs_http_modules"],
bindings = [
(name = "FINISH_WRITABLE_PORT", fromEnvironment = "FINISH_WRITABLE_PORT"),
(name = "WRITABLE_FINISHED_PORT", fromEnvironment = "WRITABLE_FINISHED_PORT"),
Expand Down
6 changes: 0 additions & 6 deletions src/workerd/api/node/util.c++
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

namespace workerd::api::node {

bool isExperimentalNodeJsCompatModule(kj::StringPtr name) {
return name == "node:fs"_kj || name == "node:http"_kj || name == "node:_http_common"_kj ||
name == "node:_http_outgoing"_kj || name == "node:_http_client"_kj ||
name == "node:_http_incoming"_kj || name == "node:_http_agent"_kj;
}

MIMEParams::MIMEParams(kj::Maybe<MimeType&> mimeType): mimeType(mimeType) {}

// Oddly, Node.js allows creating MIMEParams directly but it's not actually
Expand Down
6 changes: 6 additions & 0 deletions src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -870,4 +870,10 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
# The original version of the headers sent to edgeworker were truncated to a single
# value for specific header names, such as To and Cc. With this compat flag we will send
# the full header values to the worker script.

enableNodejsHttpModules @100 :Bool
$compatEnableFlag("enable_nodejs_http_modules")
$compatDisableFlag("disable_nodejs_http_modules")
$impliedByAfterDate(names = ["nodeJsCompat", "nodeJsCompatV2"], date = "2025-08-01");
# Enables Node.js http related modules such as node:http and node:https
}
Loading