mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
Add last-modified and if-modified-since for filemaps.
This commit is contained in:
parent
cca269ff5d
commit
72073701b0
21
src/http.c
21
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:
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user