Files
bun.sh/src/http/HTTPRequestBody.zig
pfg 83760fc446 Sort imports in all files (#21119)
Co-authored-by: taylor.fish <contact@taylor.fish>
2025-07-21 13:26:47 -07:00

39 lines
1.0 KiB
Zig

pub const HTTPRequestBody = union(enum) {
bytes: []const u8,
sendfile: SendFile,
stream: struct {
buffer: ?*ThreadSafeStreamBuffer,
ended: bool,
pub fn detach(this: *@This()) void {
if (this.buffer) |buffer| {
this.buffer = null;
buffer.deref();
}
}
},
pub fn isStream(this: *const HTTPRequestBody) bool {
return this.* == .stream;
}
pub fn deinit(this: *HTTPRequestBody) void {
switch (this.*) {
.sendfile, .bytes => {},
.stream => |*stream| stream.detach(),
}
}
pub fn len(this: *const HTTPRequestBody) usize {
return switch (this.*) {
.bytes => this.bytes.len,
.sendfile => this.sendfile.content_size,
// unknow amounts
.stream => std.math.maxInt(usize),
};
}
};
const SendFile = @import("./SendFile.zig");
const ThreadSafeStreamBuffer = @import("./ThreadSafeStreamBuffer.zig");
const std = @import("std");