mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
39 lines
1.0 KiB
Zig
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");
|