diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-10-18 13:07:23 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-10-18 13:07:23 +0000 |
commit | 1a7e3d00588725da3d8764fa9d624bc8611be070 (patch) | |
tree | 65d28b52bd1d4ccdbeb418d4d681b1999ed46b7a /src/libtipidee/tipidee_response_file.c | |
parent | 24fb88dbb023ae08adc9989bf19e0c6c569a6607 (diff) | |
download | tipidee-1a7e3d00588725da3d8764fa9d624bc8611be070.tar.xz |
Add infrastructure for custom error files
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_response_file.c')
-rw-r--r-- | src/libtipidee/tipidee_response_file.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libtipidee/tipidee_response_file.c b/src/libtipidee/tipidee_response_file.c new file mode 100644 index 0000000..0cbe8f4 --- /dev/null +++ b/src/libtipidee/tipidee_response_file.c @@ -0,0 +1,31 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/types.h> +#include <skalibs/buffer.h> + +#include <tipidee/conf.h> +#include <tipidee/method.h> +#include <tipidee/rql.h> +#include <tipidee/response.h> +#include <tipidee/util.h> + +size_t tipidee_response_file (buffer *b, tipidee_rql const *rql, unsigned int status, char const *reason, struct stat const *st, char const *ct, uint32_t options, tain const *stamp) +{ + char fmt[128] ; + size_t n = tipidee_response_status(b, rql, status, reason) ; + n += tipidee_response_header_common_put(b, options & 1, stamp) ; + if (options & 2) + { + size_t l = tipidee_response_header_lastmodified(fmt, 128, st) ; + if (l) n += buffer_putnoflush(b, fmt, l) ; + } + n += buffer_putsnoflush(b, "Content-Type: ") ; + n += buffer_putsnoflush(b, ct) ; + n += buffer_putsnoflush(b, "\r\nContent-Length: ") ; + fmt[uint64_fmt(fmt, st->st_size)] = 0 ; + n += buffer_putsnoflush(b, fmt) ; + n += buffer_putnoflush(b, "\r\n\r\n", 4) ; + return n ; +} |