[httpd/jsonapi] Add cache control headers to some json api endpoints

Adds utility functions to httpd.c for checking the request headers for
either an "If-None-Match" or an "If-Not-Modified-Since" headers. If the
header value is found and it matches the current value for the requested
resource, we return early with a http response code 403 (Not Modified).
If the request header value is not present or does not match we add the
current ETag/Last-Modified values to the response headers and process
the request normally.
This commit is contained in:
chme
2018-03-30 08:56:57 +02:00
committed by ejurgensen
parent 99a812ad9a
commit d15018cb99
3 changed files with 142 additions and 18 deletions

View File

@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <regex.h>
#include <time.h>
#include <event2/http.h>
#include <event2/buffer.h>
#include <event2/keyvalq_struct.h>
@@ -100,6 +101,12 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
void
httpd_stream_file(struct evhttp_request *req, int id);
bool
httpd_request_not_modified_since(struct evhttp_request *req, const time_t *mtime);
bool
httpd_request_etag_matches(struct evhttp_request *req, const char *etag);
/*
* Gzips an evbuffer
*