Function write [src]

Write bytes to the server. The transfer_encoding field determines how data will be sent. Must be called after send and before finish.

Prototype

pub fn write(req: *Request, bytes: []const u8) WriteError!usize

Parameters

req: *Requestbytes: []const u8

Possible Errors

ConnectionResetByPeer WriteError
MessageTooLong
NotWriteable
UnexpectedWriteFailure WriteError

Source

pub fn write(req: *Request, bytes: []const u8) WriteError!usize { switch (req.transfer_encoding) { .chunked => { if (bytes.len > 0) { try req.connection.?.writer().print("{x}\r\n", .{bytes.len}); try req.connection.?.writer().writeAll(bytes); try req.connection.?.writer().writeAll("\r\n"); } return bytes.len; }, .content_length => |*len| { if (len.* < bytes.len) return error.MessageTooLong; const amt = try req.connection.?.write(bytes); len.* -= amt; return amt; }, .none => return error.NotWriteable, } }