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

This commit is contained in:
Joris Vink 2018-06-29 09:56:04 +02:00
parent cca269ff5d
commit 72073701b0
2 changed files with 21 additions and 2 deletions

View File

@ -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:

View File

@ -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;