tiny.http.ChunkedWriter
Defined in tiny.http.
API (7)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/http/src/writer.zig:4
zig
pub const ChunkedWriter = struct { conn: *Connection, allocator: std.mem.Allocator, headers_sent: bool, pub fn init(conn: *Connection, allocator: std.mem.Allocator) ChunkedWriter { return .{ .conn = conn, .allocator = allocator, .headers_sent = false, }; } pub fn writeHeader( self: *ChunkedWriter, status: u16, status_text: []const u8, headers: []const struct { name: []const u8, value: []const u8 }, ) !void { if (self.headers_sent) return; var buf: std.ArrayListUnmanaged(u8) = .empty; defer buf.deinit(self.allocator); try buf.writer(self.allocator).print("HTTP/1.1 {d} {s}\r\n", .{ status, status_text }); for (headers) |header| { try buf.writer(self.allocator).print("{s}: {s}\r\n", .{ header.name, header.value }); } try buf.appendSlice(self.allocator, "Transfer-Encoding: chunked\r\n"); try buf.appendSlice(self.allocator, "\r\n"); try self.conn.write(buf.items); self.headers_sent = true; } pub fn chunk(self: *ChunkedWriter, data: []const u8) !void { if (data.len == 0) return; var header_buf: [32]u8 = undefined; const header = std.fmt.bufPrint(&header_buf, "{x}\r\n", .{data.len}) catch unreachable; try self.conn.write(header); try self.conn.write(data); try self.conn.write("\r\n"); } pub fn finish(self: *ChunkedWriter) !void { try self.conn.write("0\r\n\r\n"); }};Source: lib/http/src/root.zig:60
zig
pub const ChunkedWriter = writer.ChunkedWriter;Audit
| Definitions | 5 |
|---|---|
| Public names | 5 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |