diff -r 21274e5950af -r a1f4cb076d2f src/server/util/io.h --- a/src/server/util/io.h Tue Aug 13 22:14:32 2019 +0200 +++ b/src/server/util/io.h Sat Sep 24 16:26:10 2022 +0200 @@ -89,13 +89,59 @@ #endif }; +#define HTTP_STREAM_CBUF_SIZE 16 struct HttpStream { IOStream st; IOStream *fd; + + /* + * content-length or current chunk size + */ uint64_t max_read; + /* + * total bytes read (with content-length) or bytes read of current chunk + */ uint64_t read; + /* + * total bytes read with chunked transfer encoding + */ + uint64_t read_total; + /* + * read buffer (used only with chunked transfer encoding) + */ + char *readbuf; + /* + * readbuf allocated size + */ + size_t bufsize; + /* + * number of bytes currently stored in readbuf + */ + int *buflen; + /* + * current position in the read buffer + */ + int *bufpos; + /* + * current chunk_buf position + */ + int chunk_buf_pos; + /* + * buffer used only for parsing chunk headers + */ + char chunk_buf[HTTP_STREAM_CBUF_SIZE]; + /* + * chunked transfer encoding for write enabled? + */ WSBool chunked_enc; - WSBool buffered; + /* + * end of file indicator (read) + */ + WSBool read_eof; + /* + * end of file indicator (write) + */ + WSBool write_eof; }; typedef struct SSLStream { @@ -120,9 +166,15 @@ /* http stream */ IOStream* httpstream_new(pool_handle_t *pool, IOStream *fd); +int httpstream_enable_chunked_read(IOStream *st, char *buffer, size_t bufsize, int *cursize, int *pos); +int httpstream_enable_chunked_write(IOStream *st); +int httpstream_set_max_read(IOStream *st, int64_t maxread); +WSBool httpstream_eof(IOStream *st); + ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes); ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt); ssize_t net_http_read(HttpStream *st, void *buf, size_t nbytes); +ssize_t net_http_read_chunked(HttpStream *st, void *buf, size_t nbytes); ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd); void net_http_close(HttpStream *st); void net_http_finish(HttpStream *st);