aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-12 12:07:52 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-12 12:07:52 -0800
commit4bac561184b5fb83511a69f353afc9ff075acc7e (patch)
treef5eb6b92eec00b6ac260b8033c7d9360df76034e
parentedf9757650f8b498841d1a95269289b74d0b4023 (diff)
downloadbun-4bac561184b5fb83511a69f353afc9ff075acc7e.tar.gz
bun-4bac561184b5fb83511a69f353afc9ff075acc7e.tar.zst
bun-4bac561184b5fb83511a69f353afc9ff075acc7e.zip
missing
-rw-r--r--src/bun.js/api/bun/socket.zig67
-rw-r--r--src/bun.zig1
-rw-r--r--src/deps/uws.zig6
3 files changed, 49 insertions, 25 deletions
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig
index f4dcfb01c..1984daca8 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -232,38 +232,61 @@ pub const SocketConfig = struct {
}
}
- if (opts.getTruthy(globalObject, "hostname")) |hostname| {
- if (hostname.isEmptyOrUndefinedOrNull() or !hostname.isString()) {
- exception.* = JSC.toInvalidArguments("Expected \"hostname\" to be a string", .{}, globalObject).asObjectRef();
- return null;
- }
+ hostname_or_unix: {
+ if (opts.getTruthy(globalObject, "unix")) |unix_socket| {
+ if (!unix_socket.isString()) {
+ exception.* = JSC.toInvalidArguments("Expected \"unix\" to be a string", .{}, globalObject).asObjectRef();
+ return null;
+ }
- const port_value = opts.get(globalObject, "port") orelse JSValue.zero;
- if (port_value.isEmptyOrUndefinedOrNull() or !port_value.isNumber() or port_value.toInt64() > std.math.maxInt(u16) or port_value.toInt64() < 0) {
- exception.* = JSC.toInvalidArguments("Expected \"port\" to be a number between 0 and 65535", .{}, globalObject).asObjectRef();
- return null;
- }
+ hostname_or_unix = unix_socket.getZigString(globalObject).toSlice(bun.default_allocator);
- hostname_or_unix = hostname.getZigString(globalObject).toSlice(bun.default_allocator);
- port = port_value.toU16();
+ if (strings.hasPrefixComptime(hostname_or_unix.slice(), "file://") or strings.hasPrefixComptime(hostname_or_unix.slice(), "unix://") or strings.hasPrefixComptime(hostname_or_unix.slice(), "sock://")) {
+ hostname_or_unix.ptr += 7;
+ hostname_or_unix.len -|= 7;
+ }
- if (hostname_or_unix.len == 0) {
- exception.* = JSC.toInvalidArguments("Expected \"hostname\" to be a non-empty string", .{}, globalObject).asObjectRef();
- return null;
- }
- } else if (opts.getTruthy(globalObject, "unix")) |unix_socket| {
- if (unix_socket.isEmptyOrUndefinedOrNull() or !unix_socket.isString()) {
- exception.* = JSC.toInvalidArguments("Expected \"unix\" to be a string", .{}, globalObject).asObjectRef();
- return null;
+ if (hostname_or_unix.len > 0) {
+ break :hostname_or_unix;
+ }
}
- hostname_or_unix = unix_socket.getZigString(globalObject).toSlice(bun.default_allocator);
+ if (opts.getTruthy(globalObject, "hostname")) |hostname| {
+ if (!hostname.isString()) {
+ exception.* = JSC.toInvalidArguments("Expected \"hostname\" to be a string", .{}, globalObject).asObjectRef();
+ return null;
+ }
+
+ var port_value = opts.get(globalObject, "port") orelse JSValue.zero;
+ hostname_or_unix = hostname.getZigString(globalObject).toSlice(bun.default_allocator);
+
+ if (port_value.isEmptyOrUndefinedOrNull() and hostname_or_unix.len > 0) {
+ const parsed_url = bun.URL.parse(hostname_or_unix.slice());
+ if (parsed_url.getPort()) |port_num| {
+ port_value = JSValue.jsNumber(port_num);
+ hostname_or_unix.ptr = parsed_url.hostname.ptr;
+ hostname_or_unix.len = @truncate(u32, parsed_url.hostname.len);
+ }
+ }
+
+ if (port_value.isEmptyOrUndefinedOrNull() or !port_value.isNumber() or port_value.toInt64() > std.math.maxInt(u16) or port_value.toInt64() < 0) {
+ exception.* = JSC.toInvalidArguments("Expected \"port\" to be a number between 0 and 65535", .{}, globalObject).asObjectRef();
+ return null;
+ }
+
+ port = port_value.toU16();
+
+ if (hostname_or_unix.len == 0) {
+ exception.* = JSC.toInvalidArguments("Expected \"hostname\" to be a non-empty string", .{}, globalObject).asObjectRef();
+ return null;
+ }
+ }
if (hostname_or_unix.len == 0) {
exception.* = JSC.toInvalidArguments("Expected \"unix\" to be a non-empty string", .{}, globalObject).asObjectRef();
return null;
}
- } else {
+
exception.* = JSC.toInvalidArguments("Expected either \"hostname\" or \"unix\"", .{}, globalObject).asObjectRef();
return null;
}
diff --git a/src/bun.zig b/src/bun.zig
index 00bceeea4..732862e8f 100644
--- a/src/bun.zig
+++ b/src/bun.zig
@@ -765,3 +765,4 @@ pub fn zero(comptime Type: type) Type {
return @bitCast(Type, out);
}
pub const c_ares = @import("./deps/c_ares.zig");
+pub const URL = @import("./url.zig").URL;
diff --git a/src/deps/uws.zig b/src/deps/uws.zig
index 62821c85c..bfcd00e7a 100644
--- a/src/deps/uws.zig
+++ b/src/deps/uws.zig
@@ -756,10 +756,10 @@ pub const AnyWebSocket = union(enum) {
// pub fn iterateTopics(this: AnyWebSocket) {
// return uws_ws_iterate_topics(ssl_flag, this.raw(), callback: ?*const fn ([*c]const u8, usize, ?*anyopaque) callconv(.C) void, user_data: ?*anyopaque) void;
// }
- pub fn publish(this: AnyWebSocket, topic: []const u8, message: []const u8) bool {
+ pub fn publish(this: AnyWebSocket, topic: []const u8, message: []const u8, opcode: Opcode, compress: bool) bool {
return switch (this) {
- .ssl => uws_ws_publish(1, this.ssl.raw(), topic.ptr, topic.len, message.ptr, message.len),
- .tcp => uws_ws_publish(0, this.tcp.raw(), topic.ptr, topic.len, message.ptr, message.len),
+ .ssl => uws_ws_publish_with_options(1, this.ssl.raw(), topic.ptr, topic.len, message.ptr, message.len, opcode, compress),
+ .tcp => uws_ws_publish_with_options(0, this.tcp.raw(), topic.ptr, topic.len, message.ptr, message.len, opcode, compress),
};
}
pub fn publishWithOptions(ssl: bool, app: *anyopaque, topic: []const u8, message: []const u8, opcode: Opcode, compress: bool) bool {