diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/header_builder.zig | 16 | ||||
-rw-r--r-- | src/http/mime_type.zig | 2 | ||||
-rw-r--r-- | src/http/url_path.zig | 14 | ||||
-rw-r--r-- | src/http/websocket.zig | 22 | ||||
-rw-r--r-- | src/http/websocket_http_client.zig | 58 |
5 files changed, 56 insertions, 56 deletions
diff --git a/src/http/header_builder.zig b/src/http/header_builder.zig index 82e0868d9..540484655 100644 --- a/src/http/header_builder.zig +++ b/src/http/header_builder.zig @@ -22,15 +22,15 @@ pub fn allocate(this: *HeaderBuilder, allocator: std.mem.Allocator) !void { } pub fn append(this: *HeaderBuilder, name: string, value: string) void { const name_ptr = Api.StringPointer{ - .offset = @truncate(u32, this.content.len), - .length = @truncate(u32, name.len), + .offset = @as(u32, @truncate(this.content.len)), + .length = @as(u32, @truncate(name.len)), }; _ = this.content.append(name); const value_ptr = Api.StringPointer{ - .offset = @truncate(u32, this.content.len), - .length = @truncate(u32, value.len), + .offset = @as(u32, @truncate(this.content.len)), + .length = @as(u32, @truncate(value.len)), }; _ = this.content.append(value); this.entries.appendAssumeCapacity(Headers.Kv{ .name = name_ptr, .value = value_ptr }); @@ -38,8 +38,8 @@ pub fn append(this: *HeaderBuilder, name: string, value: string) void { pub fn appendFmt(this: *HeaderBuilder, name: string, comptime fmt: string, args: anytype) void { const name_ptr = Api.StringPointer{ - .offset = @truncate(u32, this.content.len), - .length = @truncate(u32, name.len), + .offset = @as(u32, @truncate(this.content.len)), + .length = @as(u32, @truncate(name.len)), }; _ = this.content.append(name); @@ -47,8 +47,8 @@ pub fn appendFmt(this: *HeaderBuilder, name: string, comptime fmt: string, args: const value = this.content.fmt(fmt, args); const value_ptr = Api.StringPointer{ - .offset = @truncate(u32, this.content.len - value.len), - .length = @truncate(u32, value.len), + .offset = @as(u32, @truncate(this.content.len - value.len)), + .length = @as(u32, @truncate(value.len)), }; this.entries.appendAssumeCapacity(Headers.Kv{ .name = name_ptr, .value = value_ptr }); diff --git a/src/http/mime_type.zig b/src/http/mime_type.zig index 3d3d9a9a9..17f6821b3 100644 --- a/src/http/mime_type.zig +++ b/src/http/mime_type.zig @@ -26,7 +26,7 @@ pub fn createHashTable(allocator: std.mem.Allocator) !Map { const decls = comptime std.meta.declarations(all); var map = Map.init(allocator); - try map.ensureTotalCapacity(@truncate(u32, decls.len)); + try map.ensureTotalCapacity(@as(u32, @truncate(decls.len))); @setEvalBranchQuota(4000); inline for (decls) |decl| { map.putAssumeCapacityNoClobber(decl.name, @field(all, decl.name)); diff --git a/src/http/url_path.zig b/src/http/url_path.zig index ac31c740d..a48700671 100644 --- a/src/http/url_path.zig +++ b/src/http/url_path.zig @@ -91,10 +91,10 @@ pub fn parse(possibly_encoded_pathname_: string) !URLPath { var first_segment_end: i16 = std.math.maxInt(i16); var last_slash: i16 = -1; - var i: i16 = @intCast(i16, decoded_pathname.len) - 1; + var i: i16 = @as(i16, @intCast(decoded_pathname.len)) - 1; while (i >= 0) : (i -= 1) { - const c = decoded_pathname[@intCast(usize, i)]; + const c = decoded_pathname[@as(usize, @intCast(i))]; switch (c) { '?' => { @@ -130,18 +130,18 @@ pub fn parse(possibly_encoded_pathname_: string) !URLPath { const extname = brk: { if (question_mark_i > -1 and period_i > -1) { period_i += 1; - break :brk decoded_pathname[@intCast(usize, period_i)..@intCast(usize, question_mark_i)]; + break :brk decoded_pathname[@as(usize, @intCast(period_i))..@as(usize, @intCast(question_mark_i))]; } else if (period_i > -1) { period_i += 1; - break :brk decoded_pathname[@intCast(usize, period_i)..]; + break :brk decoded_pathname[@as(usize, @intCast(period_i))..]; } else { break :brk &([_]u8{}); } }; - var path = if (question_mark_i < 0) decoded_pathname[1..] else decoded_pathname[1..@intCast(usize, question_mark_i)]; + var path = if (question_mark_i < 0) decoded_pathname[1..] else decoded_pathname[1..@as(usize, @intCast(question_mark_i))]; - const first_segment = decoded_pathname[1..@min(@intCast(usize, first_segment_end), decoded_pathname.len)]; + const first_segment = decoded_pathname[1..@min(@as(usize, @intCast(first_segment_end)), decoded_pathname.len)]; const is_source_map = strings.eqlComptime(extname, "map"); var backup_extname: string = extname; if (is_source_map and path.len > ".map".len) { @@ -158,7 +158,7 @@ pub fn parse(possibly_encoded_pathname_: string) !URLPath { .pathname = decoded_pathname, .first_segment = first_segment, .path = if (decoded_pathname.len == 1) "." else path, - .query_string = if (question_mark_i > -1) decoded_pathname[@intCast(usize, question_mark_i)..@intCast(usize, decoded_pathname.len)] else "", + .query_string = if (question_mark_i > -1) decoded_pathname[@as(usize, @intCast(question_mark_i))..@as(usize, @intCast(decoded_pathname.len))] else "", .needs_redirect = needs_redirect, }; } diff --git a/src/http/websocket.zig b/src/http/websocket.zig index 48a4cebf5..2fdd28451 100644 --- a/src/http/websocket.zig +++ b/src/http/websocket.zig @@ -53,20 +53,20 @@ pub const WebsocketHeader = packed struct { if (comptime Environment.allow_assert) { var buf_ = [2]u8{ 0, 0 }; var stream = std.io.fixedBufferStream(&buf_); - stream.writer().writeIntBig(u16, @bitCast(u16, header)) catch unreachable; + stream.writer().writeIntBig(u16, @as(u16, @bitCast(header))) catch unreachable; stream.pos = 0; const casted = stream.reader().readIntBig(u16) catch unreachable; - std.debug.assert(casted == @bitCast(u16, header)); - std.debug.assert(std.meta.eql(@bitCast(WebsocketHeader, casted), header)); + std.debug.assert(casted == @as(u16, @bitCast(header))); + std.debug.assert(std.meta.eql(@as(WebsocketHeader, @bitCast(casted)), header)); } - try writer.writeIntBig(u16, @bitCast(u16, header)); + try writer.writeIntBig(u16, @as(u16, @bitCast(header))); std.debug.assert(header.len == packLength(n)); } pub fn packLength(length: usize) u7 { return switch (length) { - 0...125 => @truncate(u7, length), + 0...125 => @as(u7, @truncate(length)), 126...0xFFFF => 126, else => 127, }; @@ -156,7 +156,7 @@ pub const Websocket = struct { var socket = Websocket{ .read_stream = undefined, .reader = undefined, - .stream = std.net.Stream{ .handle = @intCast(std.os.socket_t, fd) }, + .stream = std.net.Stream{ .handle = @as(std.os.socket_t, @intCast(fd)) }, .flags = flags, }; @@ -185,7 +185,7 @@ pub const Websocket = struct { // Close and send the status pub fn close(self: *Websocket, code: u16) !void { const c = if (native_endian == .Big) code else @byteSwap(code); - const data = @bitCast([2]u8, c); + const data = @as([2]u8, @bitCast(c)); _ = try self.writeMessage(.Close, &data); } @@ -230,13 +230,13 @@ pub const Websocket = struct { if (!dataframe.isValid()) return error.InvalidMessage; - try stream.writeIntBig(u16, @bitCast(u16, dataframe.header)); + try stream.writeIntBig(u16, @as(u16, @bitCast(dataframe.header))); // Write extended length if needed const n = dataframe.data.len; switch (n) { 0...126 => {}, // Included in header - 127...0xFFFF => try stream.writeIntBig(u16, @truncate(u16, n)), + 127...0xFFFF => try stream.writeIntBig(u16, @as(u16, @truncate(n))), else => try stream.writeIntBig(u64, n), } @@ -292,9 +292,9 @@ 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 = @enumFromInt(Opcode, @truncate(u4, header_bytes[0])); + header.opcode = @as(Opcode, @enumFromInt(@as(u4, @truncate(header_bytes[0])))); header.mask = header_bytes[1] & 0x80 == 0x80; - header.len = @truncate(u7, header_bytes[1]); + header.len = @as(u7, @truncate(header_bytes[1])); // Decode length var length: u64 = header.len; diff --git a/src/http/websocket_http_client.zig b/src/http/websocket_http_client.zig index 80f29525c..5bbc0a5fd 100644 --- a/src/http/websocket_http_client.zig +++ b/src/http/websocket_http_client.zig @@ -194,8 +194,8 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type { pub fn register(global: *JSC.JSGlobalObject, loop_: *anyopaque, ctx_: *anyopaque) callconv(.C) void { var vm = global.bunVM(); - var loop = @ptrCast(*uws.Loop, @alignCast(@alignOf(uws.Loop), loop_)); - var ctx: *uws.SocketContext = @ptrCast(*uws.SocketContext, ctx_); + var loop = @as(*uws.Loop, @ptrCast(@alignCast(loop_))); + var ctx: *uws.SocketContext = @as(*uws.SocketContext, @ptrCast(ctx_)); if (vm.uws_event_loop) |other| { std.debug.assert(other == loop); @@ -268,7 +268,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type { if (Socket.connect( display_host, port, - @ptrCast(*uws.SocketContext, socket_ctx), + @as(*uws.SocketContext, @ptrCast(socket_ctx)), HTTPClient, client, "tcp", @@ -366,7 +366,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type { return; } - this.to_send = this.input_body_buf[@intCast(usize, wrote)..]; + this.to_send = this.input_body_buf[@as(usize, @intCast(wrote))..]; } pub fn handleData(this: *HTTPClient, socket: Socket, data: []const u8) void { @@ -410,7 +410,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type { } }; - this.processResponse(response, body[@intCast(usize, response.bytes_read)..]); + this.processResponse(response, body[@as(usize, @intCast(response.bytes_read))..]); } pub fn handleEnd(this: *HTTPClient, socket: Socket) void { @@ -547,7 +547,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type { this.terminate(ErrorCode.failed_to_write); return; } - this.to_send = this.to_send[@min(@intCast(usize, wrote), this.to_send.len)..]; + this.to_send = this.to_send[@min(@as(usize, @intCast(wrote)), this.to_send.len)..]; } pub fn handleTimeout( this: *HTTPClient, @@ -586,7 +586,7 @@ pub const Mask = struct { mask_buf.* = globalThis.bunVM().rareData().entropySlice(4)[0..4].*; const mask = mask_buf.*; - const skip_mask = @bitCast(u32, mask) == 0; + const skip_mask = @as(u32, @bitCast(mask)) == 0; if (!skip_mask) { fillWithSkipMask(mask, output_, input_, false); } else { @@ -711,7 +711,7 @@ fn parseWebSocketHeader( // + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // | Payload Data continued ... | // +---------------------------------------------------------------+ - const header = @bitCast(WebsocketHeader, @byteSwap(@bitCast(u16, bytes))); + const header = @as(WebsocketHeader, @bitCast(@byteSwap(@as(u16, @bitCast(bytes))))); const payload = @as(usize, header.len); payload_length.* = payload; receiving_type.* = header.opcode; @@ -787,13 +787,13 @@ const Copy = union(enum) { // 0, 2, 8 byte length var to_mask = buf[content_offset..]; - var header = @bitCast(WebsocketHeader, @as(u16, 0)); + var header = @as(WebsocketHeader, @bitCast(@as(u16, 0))); // Write extended length if needed switch (how_big_is_the_length_integer) { 0 => {}, - 2 => std.mem.writeIntBig(u16, buf[2..][0..2], @truncate(u16, content_byte_len)), - 8 => std.mem.writeIntBig(u64, buf[2..][0..8], @truncate(u64, content_byte_len)), + 2 => std.mem.writeIntBig(u16, buf[2..][0..2], @as(u16, @truncate(content_byte_len))), + 8 => std.mem.writeIntBig(u64, buf[2..][0..8], @as(u64, @truncate(content_byte_len))), else => unreachable, } @@ -846,7 +846,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { outgoing_websocket: ?*CppWebSocket = null, receive_state: ReceiveState = ReceiveState.need_header, - receive_header: WebsocketHeader = @bitCast(WebsocketHeader, @as(u16, 0)), + receive_header: WebsocketHeader = @as(WebsocketHeader, @bitCast(@as(u16, 0))), receiving_type: Opcode = Opcode.ResB, ping_frame_bytes: [128 + 6]u8 = [_]u8{0} ** (128 + 6), @@ -874,9 +874,9 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { pub fn register(global: *JSC.JSGlobalObject, loop_: *anyopaque, ctx_: *anyopaque) callconv(.C) void { var vm = global.bunVM(); - var loop = @ptrCast(*uws.Loop, @alignCast(@alignOf(uws.Loop), loop_)); + var loop = @as(*uws.Loop, @ptrCast(@alignCast(loop_))); - var ctx: *uws.SocketContext = @ptrCast(*uws.SocketContext, ctx_); + var ctx: *uws.SocketContext = @as(*uws.SocketContext, @ptrCast(ctx_)); if (vm.uws_event_loop) |other| { std.debug.assert(other == loop); @@ -1312,7 +1312,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { // fast path: no backpressure, no queue, just send the bytes. if (!this.hasBackpressure()) { const wrote = socket.write(bytes, !is_closing); - const expected = @intCast(c_int, bytes.len); + const expected = @as(c_int, @intCast(bytes.len)); if (wrote == expected) { return true; } @@ -1322,7 +1322,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { return false; } - _ = this.copyToSendBuffer(bytes[@intCast(usize, wrote)..], false, is_closing); + _ = this.copyToSendBuffer(bytes[@as(usize, @intCast(wrote))..], false, is_closing); return true; } @@ -1369,7 +1369,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { this.terminate(ErrorCode.failed_to_write); return false; } - const expected = @intCast(usize, wrote); + const expected = @as(usize, @intCast(wrote)); var readable = this.send_buffer.readableSlice(0); if (readable.ptr == out_buf.ptr) { this.send_buffer.discard(expected); @@ -1388,15 +1388,15 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { return false; } - var header = @bitCast(WebsocketHeader, @as(u16, 0)); + var header = @as(WebsocketHeader, @bitCast(@as(u16, 0))); header.final = true; header.opcode = .Pong; var to_mask = this.ping_frame_bytes[6..][0..this.ping_len]; header.mask = to_mask.len > 0; - header.len = @truncate(u7, this.ping_len); - this.ping_frame_bytes[0..2].* = @bitCast([2]u8, header); + header.len = @as(u7, @truncate(this.ping_len)); + this.ping_frame_bytes[0..2].* = @as([2]u8, @bitCast(header)); if (to_mask.len > 0) { Mask.fill(this.globalThis, this.ping_frame_bytes[2..6], to_mask, to_mask); @@ -1422,12 +1422,12 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { socket.shutdownRead(); var final_body_bytes: [128 + 8]u8 = undefined; - var header = @bitCast(WebsocketHeader, @as(u16, 0)); + var header = @as(WebsocketHeader, @bitCast(@as(u16, 0))); header.final = true; header.opcode = .Close; header.mask = true; - header.len = @truncate(u7, body_len + 2); - final_body_bytes[0..2].* = @bitCast([2]u8, @bitCast(u16, header)); + header.len = @as(u7, @truncate(body_len + 2)); + final_body_bytes[0..2].* = @as([2]u8, @bitCast(@as(u16, @bitCast(header)))); var mask_buf: *[4]u8 = final_body_bytes[2..6]; std.mem.writeIntSliceBig(u16, final_body_bytes[6..8], code); @@ -1489,7 +1489,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { return; } - const opcode = @enumFromInt(Opcode, @truncate(u4, op)); + const opcode = @as(Opcode, @enumFromInt(@as(u4, @truncate(op)))); const slice = ptr[0..len]; const bytes = Copy{ .bytes = slice }; // fast path: small frame, no backpressure, attempt to send without allocating @@ -1516,7 +1516,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { // Note: 0 is valid - const opcode = @enumFromInt(Opcode, @truncate(u4, op)); + const opcode = @as(Opcode, @enumFromInt(@as(u4, @truncate(op)))); { var inline_buf: [stack_frame_size]u8 = undefined; @@ -1622,8 +1622,8 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { buffered_data: [*]u8, buffered_data_len: usize, ) callconv(.C) ?*anyopaque { - var tcp = @ptrCast(*uws.Socket, input_socket); - var ctx = @ptrCast(*uws.SocketContext, socket_ctx); + var tcp = @as(*uws.Socket, @ptrCast(input_socket)); + var ctx = @as(*uws.SocketContext, @ptrCast(socket_ctx)); var adopted = Socket.adopt( tcp, ctx, @@ -1657,9 +1657,9 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { // before the initial data handler is called outgoing.ref(); } - return @ptrCast( + return @as( *anyopaque, - adopted, + @ptrCast(adopted), ); } |