From 047472da936b76fba14a47b26d8fd47c21c0cfed Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 12 Feb 2023 13:23:32 +0100 Subject: [PATCH] Implement new_chunked_reader TODO: Implement chunked_read too --- net/http/transport.ha | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/http/transport.ha b/net/http/transport.ha index 41044eb..4f19091 100644 --- a/net/http/transport.ha +++ b/net/http/transport.ha @@ -15,8 +15,6 @@ use types; // and encode the message body appropriately. // // Most users will want this to be set to auto. -// -// TODO: Document server behavior export type transport_mode = enum { AUTO = 0, NONE, @@ -31,8 +29,6 @@ export type transport_mode = enum { // the message body appropriately. // // Most users will want this to be set to AUTO. -// -// TODO: Document server behavior export type content_mode = enum { AUTO = 0, NONE, @@ -185,14 +181,24 @@ type chunked_reader = struct { vtable: io::stream, conn: io::handle, buffer: [os::BUFSIZ]u8, + // Amount of read-ahead data in buffer pending: size, + // Length of current chunk, or zero + length: size, }; fn new_chunked_reader( conn: io::handle, buffer: []u8, ) *io::stream = { - abort(); // TODO + let rd = alloc(chunked_reader { + vtable = &chunked_reader_vtable, + conn = conn, + ... + }); + rd.buffer[..len(buffer)] = buffer[..]; + rd.pending = len(buffer); + return rd; }; const chunked_reader_vtable = io::vtable {