aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/bun-types/bun.d.ts7
-rw-r--r--src/bun.js/api/bun/socket.zig40
-rw-r--r--src/bun.js/api/server.zig23
3 files changed, 51 insertions, 19 deletions
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts
index 9dbc8ba10..a3bfa00b5 100644
--- a/packages/bun-types/bun.d.ts
+++ b/packages/bun-types/bun.d.ts
@@ -1537,6 +1537,11 @@ declare module "bun" {
dhParamsFile?: string;
/**
+ * Explicitly set a server name
+ */
+ serverName?: string;
+
+ /**
* This sets `OPENSSL_RELEASE_BUFFERS` to 1.
* It reduces overall performance but saves some memory.
* @default false
@@ -2755,7 +2760,7 @@ declare module "bun" {
interface SocketOptions<Data = unknown> {
socket: SocketHandler<Data>;
- tls?: TLSOptions;
+ tls?: boolean | TLSOptions;
data?: Data;
}
interface TCPSocketOptions<Data = undefined> extends SocketOptions<Data> {
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig
index ec8426eff..69711c8a3 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -216,7 +216,15 @@ pub const SocketConfig = struct {
var ssl: ?JSC.API.ServerConfig.SSLConfig = null;
var default_data = JSValue.zero;
- if (opts.getTruthy(globalObject, "tls")) |tls| {
+ if (opts.getTruthy(globalObject, "tls")) |tls| outer: {
+ if (tls.isBoolean()) {
+ if (tls.toBoolean()) {
+ ssl = JSC.API.ServerConfig.SSLConfig.zero;
+ }
+
+ break :outer;
+ }
+
if (JSC.API.ServerConfig.SSLConfig.inJS(globalObject, tls, exception)) |ssl_config| {
ssl = ssl_config;
} else if (exception.* != null) {
@@ -581,6 +589,19 @@ pub const Listener = struct {
socket.timeout(120000);
}
+ // pub fn addServerName(this: *Listener, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSValue {
+
+ // uws.us_socket_context_add_server_name
+ // }
+
+ // pub fn removeServerName(this: *Listener, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSValue {
+ // uws.us_socket_context_add_server_name
+ // }
+
+ // pub fn removeServerName(this: *Listener, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSValue {
+ // uws.us_socket_context_add_server_name
+ // }
+
pub fn stop(this: *Listener, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSValue {
log("close", .{});
@@ -687,22 +708,7 @@ pub const Listener = struct {
handlers.protect();
- var ctx_opts: uws.us_socket_context_options_t = undefined;
- @memset(@ptrCast([*]u8, &ctx_opts), 0, @sizeOf(uws.us_socket_context_options_t));
-
- if (ssl) |ssl_config| {
- if (ssl_config.key_file_name != null)
- ctx_opts.key_file_name = ssl_config.key_file_name;
- if (ssl_config.cert_file_name != null)
- ctx_opts.cert_file_name = ssl_config.cert_file_name;
- if (ssl_config.ca_file_name != null)
- ctx_opts.ca_file_name = ssl_config.ca_file_name;
- if (ssl_config.dh_params_file_name != null)
- ctx_opts.dh_params_file_name = ssl_config.dh_params_file_name;
- if (ssl_config.passphrase != null)
- ctx_opts.passphrase = ssl_config.passphrase;
- ctx_opts.ssl_prefer_low_memory_usage = @boolToInt(ssl_config.low_memory_mode);
- }
+ const ctx_opts: uws.us_socket_context_options_t = JSC.API.ServerConfig.SSLConfig.asUSockets(socket_config.ssl);
globalObject.bunVM().eventLoop().ensureWaker();
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 153ac5611..f47ee9fc0 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -121,6 +121,27 @@ pub const ServerConfig = struct {
passphrase: [*c]const u8 = null,
low_memory_mode: bool = false,
+ pub fn asUSockets(this_: ?SSLConfig) uws.us_socket_context_options_t {
+ var ctx_opts: uws.us_socket_context_options_t = undefined;
+ @memset(@ptrCast([*]u8, &ctx_opts), 0, @sizeOf(uws.us_socket_context_options_t));
+
+ if (this_) |ssl_config| {
+ if (ssl_config.key_file_name != null)
+ ctx_opts.key_file_name = ssl_config.key_file_name;
+ if (ssl_config.cert_file_name != null)
+ ctx_opts.cert_file_name = ssl_config.cert_file_name;
+ if (ssl_config.ca_file_name != null)
+ ctx_opts.ca_file_name = ssl_config.ca_file_name;
+ if (ssl_config.dh_params_file_name != null)
+ ctx_opts.dh_params_file_name = ssl_config.dh_params_file_name;
+ if (ssl_config.passphrase != null)
+ ctx_opts.passphrase = ssl_config.passphrase;
+ ctx_opts.ssl_prefer_low_memory_usage = @boolToInt(ssl_config.low_memory_mode);
+ }
+
+ return ctx_opts;
+ }
+
pub fn deinit(this: *SSLConfig) void {
const fields = .{
"server_name",
@@ -141,7 +162,7 @@ pub const ServerConfig = struct {
}
}
- const zero = SSLConfig{};
+ pub const zero = SSLConfig{};
pub fn inJS(global: *JSC.JSGlobalObject, obj: JSC.JSValue, exception: JSC.C.ExceptionRef) ?SSLConfig {
var result = zero;