diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-12-20 14:08:25 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-12-20 14:08:25 +0000 |
commit | 51d0fdce74aeb23ef28336037b2d35aa4c955cee (patch) | |
tree | 9c178c8e6756ec770b85efd54235cd7c2a97888f /src/libtipidee/tipidee_response_partial.c | |
parent | d2959364ef8d6bc948474a8facf497788b4e768b (diff) | |
download | tipidee-51d0fdce74aeb23ef28336037b2d35aa4c955cee.tar.xz |
Major refactors; implement ranges
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_response_partial.c')
-rw-r--r-- | src/libtipidee/tipidee_response_partial.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libtipidee/tipidee_response_partial.c b/src/libtipidee/tipidee_response_partial.c new file mode 100644 index 0000000..4411896 --- /dev/null +++ b/src/libtipidee/tipidee_response_partial.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/uint64.h> +#include <skalibs/buffer.h> + +#include <tipidee/util.h> +#include <tipidee/response.h> + +size_t tipidee_response_partial (buffer *b, tipidee_rql const *rql, struct stat const *st, uint64_t start, uint64_t len, char const *ct, tipidee_response_header const *rhdr, uint32_t rhdrn, uint32_t options, tain const *stamp) +{ + tipidee_defaulttext dt ; + size_t n ; + char fmt[UINT64_FMT] ; + if (!tipidee_util_defaulttext(206, &dt)) return 0 ; + n = tipidee_response_file(b, rql, 206, dt.reason, st, len, ct, rhdr, rhdrn, options, stamp) ; + if (len) + { + n += buffer_putsnoflush(b, "Content-Range: bytes ") ; + n += buffer_putnoflush(b, fmt, uint64_fmt(fmt, start)) ; + n += buffer_putnoflush(b, "-", 1) ; + n += buffer_putnoflush(b, fmt, uint64_fmt(fmt, start + len - 1)) ; + n += buffer_putnoflush(b, "/", 1) ; + n += buffer_putnoflush(b, fmt, uint64_fmt(fmt, st->st_size)) ; + n += buffer_putnoflush(b, "\r\n", 2) ; + } + return n ; +} |