diff options
Diffstat (limited to 'src/tipideed/regular.c')
-rw-r--r-- | src/tipideed/regular.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/tipideed/regular.c b/src/tipideed/regular.c index 845f12b..aa937ad 100644 --- a/src/tipideed/regular.c +++ b/src/tipideed/regular.c @@ -4,7 +4,6 @@ #include <errno.h> -#include <skalibs/uint64.h> #include <skalibs/stat.h> #include <skalibs/types.h> #include <skalibs/buffer.h> @@ -18,24 +17,12 @@ #include <tipidee/log.h> #include "tipideed-internal.h" -int respond_regular (tipidee_rql const *rql, char const *fn, struct stat const *st, tipidee_resattr const *ra) +int respond_regular (tipidee_rql const *rql, char const *docroot, char const *fn, struct stat const *st, tipidee_resattr const *ra) { - tain deadline ; - char fmt[128] ; - size_t n = tipidee_response_status(buffer_1, rql, 200, "OK") ; - n += tipidee_response_header_common_put_g(buffer_1, !g.cont) ; - { - size_t l = tipidee_response_header_lastmodified(fmt, 128, st) ; - if (l) n += buffer_putnoflush(buffer_1, fmt, l) ; - } - n += buffer_putsnoflush(buffer_1, "Content-Type: ") ; - n += buffer_putsnoflush(buffer_1, ra->content_type) ; - n += buffer_putsnoflush(buffer_1, "\r\nContent-Length: ") ; - fmt[uint64_fmt(fmt, st->st_size)] = 0 ; - n += buffer_putsnoflush(buffer_1, fmt) ; - n += buffer_putnoflush(buffer_1, "\r\n\r\n", 4) ; if (rql->m == TIPIDEE_METHOD_HEAD) { + tain deadline ; + tipidee_response_file_g(buffer_1, rql, 200, "OK", st, ra->content_type, 2 | !g.cont) ; tipidee_log_answer(g.logv, rql, 200, st->st_size) ; tain_add_g(&deadline, &g.writetto) ; if (!buffer_timed_flush_g(buffer_1, &deadline)) @@ -46,14 +33,14 @@ int respond_regular (tipidee_rql const *rql, char const *fn, struct stat const * int fd = open_read(fn) ; if (fd == -1) { - buffer_unput(buffer_1, n) ; if (errno == EACCES) { - respond_403(rql) ; + respond_403(rql, docroot) ; return 0 ; } - else die500sys(rql, 111, "open ", fn) ; + else die500sys(rql, 111, docroot, "open ", fn) ; } + tipidee_response_file_g(buffer_1, rql, 200, "OK", st, ra->content_type, 2 | !g.cont) ; tipidee_log_answer(g.logv, rql, 200, st->st_size) ; send_file(fd, st->st_size, fn) ; fd_close(fd) ; |