aboutsummaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/http.zig37
-rw-r--r--src/http/websocket.zig8
-rw-r--r--src/http/websocket_http_client.zig26
-rw-r--r--src/http_client_async.zig41
4 files changed, 53 insertions, 59 deletions
diff --git a/src/http.zig b/src/http.zig
index d2924b804..827bfa6de 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -437,7 +437,7 @@ pub const RequestContext = struct {
.reason = step,
.cwd = this.bundler.fs.top_level_dir,
.problems = Api.Problems{
- .code = @truncate(u16, @errorToInt(err)),
+ .code = @truncate(u16, @intFromError(err)),
.name = @errorName(err),
.exceptions = exceptions,
.build = try log.toAPI(allocator),
@@ -559,7 +559,7 @@ pub const RequestContext = struct {
var stat = file.stat() catch return null;
var absolute_path = resolve_path.joinAbs(this.bundler.options.routes.static_dir, .auto, relative_unrooted_path);
- if (stat.kind == .SymLink) {
+ if (stat.kind == .sym_link) {
file.* = std.fs.openFileAbsolute(absolute_path, .{ .mode = .read_only }) catch return null;
absolute_path = bun.getFdPath(
@@ -570,7 +570,7 @@ pub const RequestContext = struct {
stat = file.stat() catch return null;
}
- if (stat.kind != .File) {
+ if (stat.kind != .file) {
file.close();
return null;
}
@@ -1431,7 +1431,7 @@ pub const RequestContext = struct {
JavaScript.API.Bun.flushCSSImports();
vm.flush();
- Output.printElapsed(@intToFloat(f64, (handler.start_timer.read())) / std.time.ns_per_ms);
+ Output.printElapsed(@floatFromInt(f64, (handler.start_timer.read())) / std.time.ns_per_ms);
if (vm.bundler.options.framework.?.display_name.len > 0) {
Output.prettyError(
@@ -2000,11 +2000,7 @@ pub const RequestContext = struct {
// sometimes the final byte has incorrect data
// we never end up using all those bytes
if (handler.message_buffer.list.items.len > 0) {
- @memset(
- handler.message_buffer.list.items.ptr,
- 0,
- @min(handler.message_buffer.list.items.len, 128),
- );
+ @memset(handler.message_buffer.list.items[0..@min(handler.message_buffer.list.items.len, 128)], 0);
}
const build_result = handler.builder.build(request_id, cmd.timestamp, arena.allocator()) catch |err| {
if (err == error.MissingWatchID) {
@@ -2087,7 +2083,7 @@ pub const RequestContext = struct {
socket_buffers[2] = iovec(build_result.bytes);
// we reuse the accept key buffer
// so we have a pointer that is not stack memory
- handler.accept_key[0..@sizeOf(usize)].* = @bitCast([@sizeOf(usize)]u8, std.hash.Wyhash.hash(0, build_result.bytes));
+ handler.accept_key[0..@sizeOf(usize)].* = @bitCast([@sizeOf(usize)]u8, bun.hash(build_result.bytes));
socket_buffers[3] = iovec(handler.accept_key[0..4]);
socket_buffer_count = 4;
}
@@ -2110,7 +2106,7 @@ pub const RequestContext = struct {
else => {
Output.prettyErrorln(
"<r>[Websocket]: Unknown cmd: <b>{d}<r>. This might be a version mismatch. Try updating your node_modules.bun",
- .{@enumToInt(cmd.kind)},
+ .{@intFromEnum(cmd.kind)},
);
},
}
@@ -2187,7 +2183,7 @@ pub const RequestContext = struct {
};
pub fn writeETag(this: *RequestContext, buffer: anytype) !bool {
- const strong_etag = std.hash.Wyhash.hash(0, buffer);
+ const strong_etag = bun.hash(buffer);
const etag_content_slice = std.fmt.bufPrintIntToSlice(strong_etag_buffer[0..49], strong_etag, 16, .upper, .{});
this.appendHeader("ETag", etag_content_slice);
@@ -2404,7 +2400,7 @@ pub const RequestContext = struct {
// Always cache css & json files, even big ones
// css is especially important because we want to try and skip having the browser parse it whenever we can
if (buf.len < 16 * 16 * 16 * 16 or chunky._loader == .css or chunky._loader == .json) {
- const strong_etag = std.hash.Wyhash.hash(0, buf);
+ const strong_etag = bun.hash(buf);
const etag_content_slice = std.fmt.bufPrintIntToSlice(strong_etag_buffer[0..49], strong_etag, 16, .upper, .{});
chunky.rctx.appendHeader("ETag", etag_content_slice);
@@ -2538,7 +2534,7 @@ pub const RequestContext = struct {
.css => try ctx.sendNoContent(),
.toml, .js, .jsx, .ts, .tsx, .json => {
const buf = "export default {};";
- const strong_etag = comptime std.hash.Wyhash.hash(0, buf);
+ const strong_etag = comptime bun.hash(buf);
const etag_content_slice = std.fmt.bufPrintIntToSlice(strong_etag_buffer[0..49], strong_etag, 16, .upper, .{});
ctx.appendHeader("ETag", etag_content_slice);
@@ -3388,10 +3384,10 @@ pub const Server = struct {
break :brk path_string.slice();
} else {
var file_path_without_trailing_slash = std.mem.trimRight(u8, file_path, std.fs.path.sep_str);
- @memcpy(&_on_file_update_path_buf, file_path_without_trailing_slash.ptr, file_path_without_trailing_slash.len);
+ @memcpy(_on_file_update_path_buf[0..file_path_without_trailing_slash.len], file_path_without_trailing_slash);
_on_file_update_path_buf[file_path_without_trailing_slash.len] = std.fs.path.sep;
- @memcpy(_on_file_update_path_buf[file_path_without_trailing_slash.len + 1 ..].ptr, changed_name.ptr, changed_name.len);
+ @memcpy(_on_file_update_path_buf[file_path_without_trailing_slash.len + 1 .. changed_name.len], changed_name);
const path_slice = _on_file_update_path_buf[0 .. file_path_without_trailing_slash.len + changed_name.len + 1];
file_hash = Watcher.getHash(path_slice);
break :brk path_slice;
@@ -3445,12 +3441,9 @@ pub const Server = struct {
.kernel_backlog = 1280,
});
defer listener.deinit();
- server.websocket_threadpool.stack_size = @truncate(
- u32,
- @min(
- @max(128_000, Fs.FileSystem.RealFS.Limit.stack),
- 4_000_000,
- ),
+ server.websocket_threadpool.stack_size = @min(
+ @max(128_000, Fs.FileSystem.RealFS.Limit.stack),
+ 4_000_000,
);
// listener.setFastOpen(true) catch {};
diff --git a/src/http/websocket.zig b/src/http/websocket.zig
index 98410d57c..48a4cebf5 100644
--- a/src/http/websocket.zig
+++ b/src/http/websocket.zig
@@ -34,7 +34,7 @@ pub const Opcode = enum(u4) {
ResF = 0xF,
pub fn isControl(opcode: Opcode) bool {
- return @enumToInt(opcode) & 0x8 != 0;
+ return @intFromEnum(opcode) & 0x8 != 0;
}
};
@@ -261,7 +261,7 @@ pub const Websocket = struct {
}
pub fn read(self: *Websocket) !WebsocketDataFrame {
- @memset(&self.buf, 0, self.buf.len);
+ @memset(&self.buf, 0);
// Read and retry if we hit the end of the stream buffer
var start = try self.stream.read(&self.buf);
@@ -274,7 +274,7 @@ pub const Websocket = struct {
}
pub fn eatAt(self: *Websocket, offset: usize, _len: usize) []u8 {
- const len = std.math.min(self.read_stream.buffer.len, _len);
+ const len = @min(self.read_stream.buffer.len, _len);
self.read_stream.pos = len;
return self.read_stream.buffer[offset..len];
}
@@ -292,7 +292,7 @@ pub const Websocket = struct {
// header.rsv1 = header_bytes[0] & 0x40 == 0x40;
// header.rsv2 = header_bytes[0] & 0x20;
// header.rsv3 = header_bytes[0] & 0x10;
- header.opcode = @intToEnum(Opcode, @truncate(u4, header_bytes[0]));
+ header.opcode = @enumFromInt(Opcode, @truncate(u4, header_bytes[0]));
header.mask = header_bytes[1] & 0x80 == 0x80;
header.len = @truncate(u7, header_bytes[1]);
diff --git a/src/http/websocket_http_client.zig b/src/http/websocket_http_client.zig
index e1bd42984..e79c353e3 100644
--- a/src/http/websocket_http_client.zig
+++ b/src/http/websocket_http_client.zig
@@ -77,9 +77,9 @@ fn buildRequestBody(
};
if (client_protocol.len > 0)
- client_protocol_hash.* = std.hash.Wyhash.hash(0, static_headers[1].value);
+ client_protocol_hash.* = bun.hash(static_headers[1].value);
- const headers_ = static_headers[0 .. 1 + @as(usize, @boolToInt(client_protocol.len > 0))];
+ const headers_ = static_headers[0 .. 1 + @as(usize, @intFromBool(client_protocol.len > 0))];
const pathname_ = pathname.slice();
const host_ = host.slice();
@@ -289,7 +289,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
this.clearData();
if (!this.tcp.isEstablished()) {
- _ = uws.us_socket_close_connecting(comptime @as(c_int, @boolToInt(ssl)), this.tcp.socket);
+ _ = uws.us_socket_close_connecting(comptime @as(c_int, @intFromBool(ssl)), this.tcp.socket);
} else {
this.tcp.close(0, null);
}
@@ -387,7 +387,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
const to_write = remain[0..@min(remain.len, data.len)];
if (data.len > 0 and to_write.len > 0) {
- @memcpy(remain.ptr, data.ptr, to_write.len);
+ @memcpy(remain[0..to_write.len], data[0..to_write.len]);
this.body_written += to_write.len;
}
@@ -465,7 +465,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
},
"Sec-WebSocket-Protocol".len => {
if (strings.eqlCaseInsensitiveASCII(header.name, "Sec-WebSocket-Protocol", false)) {
- if (this.websocket_protocol == 0 or std.hash.Wyhash.hash(0, header.value) != this.websocket_protocol) {
+ if (this.websocket_protocol == 0 or bun.hash(header.value) != this.websocket_protocol) {
this.terminate(ErrorCode.mismatch_client_protocol);
return;
}
@@ -524,7 +524,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
this.terminate(ErrorCode.invalid_response);
return;
};
- if (remain_buf.len > 0) @memcpy(overflow.ptr, remain_buf.ptr, remain_buf.len);
+ if (remain_buf.len > 0) @memcpy(overflow[0..remain_buf.len], remain_buf);
}
this.clearData();
@@ -775,7 +775,7 @@ const Copy = union(enum) {
if (this == .raw) {
std.debug.assert(buf.len >= this.raw.len);
std.debug.assert(buf.ptr != this.raw.ptr);
- @memcpy(buf.ptr, this.raw.ptr, this.raw.len);
+ @memcpy(buf[0..this.raw.len], this.raw);
return;
}
@@ -914,7 +914,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
return;
if (!this.tcp.isEstablished()) {
- _ = uws.us_socket_close_connecting(comptime @as(c_int, @boolToInt(ssl)), this.tcp.socket);
+ _ = uws.us_socket_close_connecting(comptime @as(c_int, @intFromBool(ssl)), this.tcp.socket);
} else {
this.tcp.close(0, null);
}
@@ -1027,7 +1027,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
std.debug.assert(data_.len > 0);
var writable = this.receive_buffer.writableWithSize(data_.len) catch unreachable;
- @memcpy(writable.ptr, data_.ptr, data_.len);
+ @memcpy(writable[0..data_.len], data_);
this.receive_buffer.update(data_.len);
if (left_in_fragment >= data_.len and left_in_fragment - data_.len - this.receive_pending_chunk_len == 0) {
@@ -1177,10 +1177,10 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
.ping => {
const ping_len = @min(data.len, @min(receive_body_remain, 125));
- this.ping_len = @truncate(u8, ping_len);
+ this.ping_len = ping_len;
if (ping_len > 0) {
- @memcpy(this.ping_frame_bytes[6..], data.ptr, ping_len);
+ @memcpy(this.ping_frame_bytes[6..][0..ping_len], data[0..ping_len]);
data = data[ping_len..];
}
@@ -1379,7 +1379,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
std.mem.writeIntSliceBig(u16, final_body_bytes[6..8], code);
if (body) |data| {
- if (body_len > 0) @memcpy(final_body_bytes[8..], data, body_len);
+ if (body_len > 0) @memcpy(final_body_bytes[8..][0..body_len], data[0..body_len]);
}
// we must mask the code
@@ -1565,7 +1565,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
this.adopted.receive_buffer.ensureUnusedCapacity(this.slice.len) catch return;
var writable = this.adopted.receive_buffer.writableSlice(0);
- @memcpy(writable.ptr, this.slice.ptr, this.slice.len);
+ @memcpy(writable[0..this.slice.len], this.slice);
this.adopted.handleData(this.adopted.tcp, writable);
}
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index fe5f34f48..a1962a8b9 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -42,7 +42,7 @@ const HiveArray = @import("./hive_array.zig").HiveArray;
const Batch = NetworkThread.Batch;
const TaggedPointerUnion = @import("./tagged_pointer.zig").TaggedPointerUnion;
const DeadSocket = opaque {};
-var dead_socket = @intToPtr(*DeadSocket, 1);
+var dead_socket = @ptrFromInt(*DeadSocket, 1);
//TODO: this needs to be freed when Worker Threads are implemented
var socket_async_http_abort_tracker = std.AutoArrayHashMap(u32, *uws.Socket).init(bun.default_allocator);
var async_http_id: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(0);
@@ -208,7 +208,7 @@ const ProxyTunnel = struct {
_ = BoringSSL.BIO_push(out_bio, proxy_bio);
} else {
// socket output bio for non-TLS -> TLS
- var fd = @intCast(c_int, @ptrToInt(socket.getNativeHandle()));
+ var fd = @intCast(c_int, @intFromPtr(socket.getNativeHandle()));
out_bio = BoringSSL.BIO_new_fd(fd, BoringSSL.BIO_NOCLOSE);
}
@@ -306,7 +306,7 @@ fn NewHTTPContext(comptime ssl: bool) type {
HTTPClient,
PooledSocket,
});
- const ssl_int = @as(c_int, @boolToInt(ssl));
+ const ssl_int = @as(c_int, @intFromBool(ssl));
const MAX_KEEPALIVE_HOSTNAME = 128;
@@ -320,7 +320,8 @@ fn NewHTTPContext(comptime ssl: bool) type {
pub fn init(this: *@This()) !void {
var opts: uws.us_socket_context_options_t = undefined;
- @memset(@ptrCast([*]u8, &opts), 0, @sizeOf(uws.us_socket_context_options_t));
+ const size = @sizeOf(uws.us_socket_context_options_t);
+ @memset(@ptrCast([*]u8, &opts)[0..size], 0);
this.us_socket_context = uws.us_create_socket_context(ssl_int, http_thread.loop, @sizeOf(usize), opts).?;
if (comptime ssl) {
this.sslCtx().setup();
@@ -337,7 +338,7 @@ fn NewHTTPContext(comptime ssl: bool) type {
/// Attempt to keep the socket alive by reusing it for another request.
/// If no space is available, close the socket.
pub fn releaseSocket(this: *@This(), socket: HTTPSocket, hostname: []const u8, port: u16) void {
- log("releaseSocket(0x{})", .{bun.fmt.hexIntUpper(@ptrToInt(socket.socket))});
+ log("releaseSocket(0x{})", .{bun.fmt.hexIntUpper(@intFromPtr(socket.socket))});
if (comptime Environment.allow_assert) {
std.debug.assert(!socket.isClosed());
@@ -354,11 +355,11 @@ fn NewHTTPContext(comptime ssl: bool) type {
socket.timeout(300);
pending.http_socket = socket;
- @memcpy(&pending.hostname_buf, hostname.ptr, hostname.len);
+ @memcpy(pending.hostname_buf[0..hostname.len], hostname);
pending.hostname_len = @truncate(u8, hostname.len);
pending.port = port;
- log("Keep-Alive release {s}:{d} (0x{})", .{ hostname, port, @ptrToInt(socket.socket) });
+ log("Keep-Alive release {s}:{d} (0x{})", .{ hostname, port, @intFromPtr(socket.socket) });
return;
}
}
@@ -778,7 +779,7 @@ pub fn onOpen(
var hostname_needs_free = false;
if (!strings.isIPAddress(_hostname)) {
if (_hostname.len < temp_hostname.len) {
- @memcpy(&temp_hostname, _hostname.ptr, _hostname.len);
+ @memcpy(temp_hostname[0.._hostname.len], _hostname);
temp_hostname[_hostname.len] = 0;
hostname = temp_hostname[0.._hostname.len :0];
} else {
@@ -1393,7 +1394,7 @@ pub const AsyncHTTP = struct {
if (proxy.password.len > 0 and proxy.password.len < 4096) {
// decode password
var password_buffer: [4096]u8 = undefined;
- std.mem.set(u8, &password_buffer, 0);
+ @memset(&password_buffer, 0);
var password_stream = std.io.fixedBufferStream(&password_buffer);
var password_writer = password_stream.writer();
const PassWriter = @TypeOf(password_writer);
@@ -1405,7 +1406,7 @@ pub const AsyncHTTP = struct {
// Decode username
var username_buffer: [4096]u8 = undefined;
- std.mem.set(u8, &username_buffer, 0);
+ @memset(&username_buffer, 0);
var username_stream = std.io.fixedBufferStream(&username_buffer);
var username_writer = username_stream.writer();
const UserWriter = @TypeOf(username_writer);
@@ -1426,7 +1427,7 @@ pub const AsyncHTTP = struct {
} else {
//Decode username
var username_buffer: [4096]u8 = undefined;
- std.mem.set(u8, &username_buffer, 0);
+ @memset(&username_buffer, 0);
var username_stream = std.io.fixedBufferStream(&username_buffer);
var username_writer = username_stream.writer();
const UserWriter = @TypeOf(username_writer);
@@ -1469,7 +1470,7 @@ pub const AsyncHTTP = struct {
if (proxy.password.len > 0 and proxy.password.len < 4096) {
// decode password
var password_buffer: [4096]u8 = undefined;
- std.mem.set(u8, &password_buffer, 0);
+ @memset(&password_buffer, 0);
var password_stream = std.io.fixedBufferStream(&password_buffer);
var password_writer = password_stream.writer();
const PassWriter = @TypeOf(password_writer);
@@ -1481,7 +1482,7 @@ pub const AsyncHTTP = struct {
// Decode username
var username_buffer: [4096]u8 = undefined;
- std.mem.set(u8, &username_buffer, 0);
+ @memset(&username_buffer, 0);
var username_stream = std.io.fixedBufferStream(&username_buffer);
var username_writer = username_stream.writer();
const UserWriter = @TypeOf(username_writer);
@@ -1503,7 +1504,7 @@ pub const AsyncHTTP = struct {
} else {
//Decode username
var username_buffer: [4096]u8 = undefined;
- std.mem.set(u8, &username_buffer, 0);
+ @memset(&username_buffer, 0);
var username_stream = std.io.fixedBufferStream(&username_buffer);
var username_writer = username_stream.writer();
const UserWriter = @TypeOf(username_writer);
@@ -1872,7 +1873,7 @@ pub fn onWritable(this: *HTTPClient, comptime is_first_call: bool, comptime is_s
var remain = list.items.ptr[list.items.len..list.capacity];
const wrote = @min(remain.len, this.state.request_body.len);
std.debug.assert(wrote > 0);
- @memcpy(remain.ptr, this.state.request_body.ptr, wrote);
+ @memcpy(remain[0..wrote], this.state.request_body[0..wrote]);
list.items.len += wrote;
}
@@ -2021,7 +2022,7 @@ pub fn onWritable(this: *HTTPClient, comptime is_first_call: bool, comptime is_s
var remain = list.items.ptr[list.items.len..list.capacity];
const wrote = @min(remain.len, this.state.request_body.len);
std.debug.assert(wrote > 0);
- @memcpy(remain.ptr, this.state.request_body.ptr, wrote);
+ @memcpy(remain[0..wrote], this.state.request_body[0..wrote]);
list.items.len += wrote;
}
@@ -2582,8 +2583,8 @@ fn handleResponseBodyFromSinglePacket(this: *HTTPClient, incoming_data: []const
if (this.state.encoding.isCompressed()) {
var body_buffer = this.state.body_out_str.?;
if (body_buffer.list.capacity == 0) {
- const min = @min(@ceil(@intToFloat(f64, incoming_data.len) * 1.5), @as(f64, 1024 * 1024 * 2));
- try body_buffer.growBy(@max(@floatToInt(usize, min), 32));
+ const min = @min(@ceil(@floatFromInt(f64, incoming_data.len) * 1.5), @as(f64, 1024 * 1024 * 2));
+ try body_buffer.growBy(@max(@intFromFloat(usize, min), 32));
}
try ZlibPool.decompress(incoming_data, body_buffer, default_allocator);
@@ -2737,7 +2738,7 @@ fn handleResponseBodyChunkedEncodingFromSinglePacket(
buffer = bun.constStrToU8(incoming_data);
} else {
buffer = single_packet_small_buffer[0..incoming_data.len];
- @memcpy(buffer.ptr, incoming_data.ptr, incoming_data.len);
+ @memcpy(buffer[0..incoming_data.len], incoming_data);
}
var bytes_decoded = incoming_data.len;
@@ -2871,7 +2872,7 @@ pub fn handleResponseMetadata(
return error.UnsupportedRedirectProtocol;
}
- if ((protocol_name.len * @as(usize, @boolToInt(is_protocol_relative))) + location.len > url_buf.data.len) {
+ if ((protocol_name.len * @as(usize, @intFromBool(is_protocol_relative))) + location.len > url_buf.data.len) {
return error.RedirectURLTooLong;
}