summaryrefslogtreecommitdiff
path: root/src/tipideed/regular.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tipideed/regular.c')
-rw-r--r--src/tipideed/regular.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/tipideed/regular.c b/src/tipideed/regular.c
index df4b157..5af364d 100644
--- a/src/tipideed/regular.c
+++ b/src/tipideed/regular.c
@@ -1,8 +1,11 @@
/* ISC license. */
+#include <skalibs/bsdsnowflake.h>
+
#include <errno.h>
#include <skalibs/uint64.h>
+#include <skalibs/stat.h>
#include <skalibs/types.h>
#include <skalibs/buffer.h>
#include <skalibs/djbunix.h>
@@ -14,21 +17,23 @@
#include <tipidee/response.h>
#include "tipideed-internal.h"
-int respond_regular (tipidee_rql const *rql, char const *fn, uint64_t size, tipidee_resattr const *ra)
+int respond_regular (tipidee_rql const *rql, char const *fn, struct stat const *st, tipidee_resattr const *ra)
{
tain deadline ;
+ char fmt[128] ;
size_t n = tipidee_response_status_line(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: ") ;
- {
- char fmt[UINT64_FMT] ;
- fmt[uint64_fmt(fmt, size)] = 0 ;
- n += buffer_putsnoflush(buffer_1, fmt) ;
- log_regular(fn, fmt, rql->m == TIPIDEE_METHOD_HEAD, ra->content_type) ;
- }
+ fmt[uint64_fmt(fmt, st->st_size)] = 0 ;
+ n += buffer_putsnoflush(buffer_1, fmt) ;
n += buffer_putnoflush(buffer_1, "\r\n\r\n", 4) ;
+ log_regular(fn, fmt, rql->m == TIPIDEE_METHOD_HEAD, ra->content_type) ;
if (rql->m == TIPIDEE_METHOD_HEAD)
{
tain_add_g(&deadline, &g.writetto) ;
@@ -48,8 +53,26 @@ int respond_regular (tipidee_rql const *rql, char const *fn, uint64_t size, tipi
}
else die500sys(rql, 111, "open ", fn) ;
}
- send_file(fd, size, fn) ;
+ send_file(fd, st->st_size, fn) ;
fd_close(fd) ;
}
return 0 ;
}
+
+int respond_304 (tipidee_rql const *rql, char const *fn, struct stat const *st)
+{
+ tain deadline ;
+ char fmt[128] ;
+ size_t n = tipidee_response_status_line(buffer_1, rql, "304 Not Modified") ;
+ 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_putnoflush(buffer_1, "\r\n", 2) ;
+ log_304(fn) ;
+ tain_add_g(&deadline, &g.writetto) ;
+ if (!buffer_timed_flush_g(buffer_1, &deadline))
+ strerr_diefu1sys(111, "write to stdout") ;
+ return 0 ;
+}