kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 72073701b08c9e299dcd9bc52f95bee7dc6f3d8d
parent cca269ff5d04a0ceabaf482d55f6d3449f8d5e40
Author: Joris Vink <joris@coders.se>
Date:   Fri, 29 Jun 2018 09:56:04 +0200

Add last-modified and if-modified-since for filemaps.

Diffstat:
src/http.c | 21++++++++++++++++++++-
src/utils.c | 2+-
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/http.c b/src/http.c @@ -501,7 +501,10 @@ void http_response_fileref(struct http_request *req, int status, struct kore_fileref *ref) { - const char *media_type; + struct tm *tm; + time_t mtime; + char tbuf[128]; + const char *media_type, *modified; if (req->owner == NULL) return; @@ -510,6 +513,22 @@ http_response_fileref(struct http_request *req, int status, if (media_type != NULL) http_response_header(req, "content-type", media_type); + if (http_request_header(req, "if-modified-since", &modified)) { + mtime = kore_date_to_time(modified); + if (mtime == ref->mtime) { + kore_fileref_release(ref); + http_response(req, HTTP_STATUS_NOT_MODIFIED, NULL, 0); + return; + } + } + + if ((tm = gmtime(&ref->mtime)) != NULL) { + if (strftime(tbuf, sizeof(tbuf), + "%a, %d %b %Y %H:%M:%S GMT", tm) > 0) { + http_response_header(req, "last-modified", tbuf); + } + } + req->status = status; switch (req->owner->proto) { case CONN_PROTO_HTTP: diff --git a/src/utils.c b/src/utils.c @@ -300,7 +300,7 @@ kore_strip_chars(char *in, const char strip, char **out) } time_t -kore_date_to_time(char *http_date) +kore_date_to_time(const char *http_date) { time_t t; int err, i;