From 3d334dca671898241732dbc0ef6838b768308da7 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 21 Sep 2023 02:18:35 +0000 Subject: Implement If-Modified-Since Signed-off-by: Laurent Bercot --- src/tipideed/tipideed.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/tipideed/tipideed.c') diff --git a/src/tipideed/tipideed.c b/src/tipideed/tipideed.c index 8c1e16e..5b6db10 100644 --- a/src/tipideed/tipideed.c +++ b/src/tipideed/tipideed.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include + #include #include #include #include -#include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -286,8 +288,17 @@ static inline int serve (tipidee_rql *rql, char const *docroot, size_t docrootle return respond_options(rql, ra.iscgi) ; else if (ra.iscgi) return respond_cgi(rql, fn, docrootlen, infopath, uribuf, hdr, &ra, body, bodylen) ; - else - return respond_regular(rql, fn, st.st_size, &ra) ; + + infopath = tipidee_headers_search(hdr, "If-Modified-Since") ; + if (infopath) + { + tain wanted, actual ; + if (tipidee_util_httpdate(infopath, &wanted) + && tain_from_timespec(&actual, &st.st_mtim) + && tain_less(&actual, &wanted)) + return respond_304(rql, fn, &st) ; + } + return respond_regular(rql, fn, &st, &ra) ; } int main (int argc, char const *const *argv, char const *const *envp) @@ -495,7 +506,7 @@ int main (int argc, char const *const *argv, char const *const *envp) } case TIPIDEE_TRANSFERCODING_CHUNKED : { - if (!tipidee_chunked_read_g(buffer_0, &bodysa, g.maxrqbody, &deadline)) + if (!tipidee_util_chunked_read_g(buffer_0, &bodysa, g.maxrqbody, &deadline)) { if (error_temp(errno)) die500sys(&rql, 111, "decode chunked body") ; else if (errno == EMSGSIZE) exit_413(&rql, "Request body too large") ; -- cgit v1.3.1