Fix caching behaviour
This commit is contained in:
@@ -61,11 +61,6 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
|
||||
fcgi_cnx_buf.r_addr = ctx->socket.addr;
|
||||
fcgi_cnx_buf.r_host = (ctx->host[0] != 0) ? ctx->host : NULL;
|
||||
|
||||
struct stat statbuf;
|
||||
stat(uri->filename, &statbuf);
|
||||
char *last_modified = http_format_date(statbuf.st_mtime, buf, sizeof(buf));
|
||||
http_add_header_field(&res->hdr, "Last-Modified", last_modified);
|
||||
|
||||
res->status = http_get_status(200);
|
||||
if (fastcgi_init(&fcgi_cnx_buf, mode, ctx->req_num, client, req, uri) != 0) {
|
||||
fastcgi_close_cnx(&fcgi_cnx_buf);
|
||||
|
@@ -213,23 +213,27 @@ static int local_handler(client_ctx_t *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
buf1[0] = 0;
|
||||
if (uri->meta->etag[0] != 0) {
|
||||
strcpy(buf1, uri->meta->etag);
|
||||
buf1[0] = '"';
|
||||
strcpy(buf1 + 1, uri->meta->etag);
|
||||
if (enc) {
|
||||
strcat(buf1, "-");
|
||||
strcat(buf1, (enc & COMPRESS_BR) ? "br" : (enc & COMPRESS_GZ) ? "gzip" : "");
|
||||
}
|
||||
strcat(buf1, "\"");
|
||||
http_add_header_field(&res->hdr, "ETag", buf1);
|
||||
}
|
||||
|
||||
http_add_header_field(&res->hdr, "Cache-Control", mime_is_text(uri->meta->type) ? "public, max-age=3600" : "public, max-age=86400");
|
||||
http_add_header_field(&res->hdr, "Cache-Control", mime_is_text(uri->meta->type) ? "public, must-revalidate, max-age=3600" : "public, must-revalidate, max-age=86400");
|
||||
|
||||
const char *if_modified_since = http_get_header_field(&req->hdr, "If-Modified-Since");
|
||||
const char *if_none_match = http_get_header_field(&req->hdr, "If-None-Match");
|
||||
if ((if_none_match != NULL && !strcontains(if_none_match, uri->meta->etag)) ||
|
||||
if ((if_none_match != NULL && strcontains(if_none_match, buf1)) ||
|
||||
(accept_if_modified_since && streq(if_modified_since, last_modified)))
|
||||
{
|
||||
res->status = http_get_status(304);
|
||||
ctx->content_length = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -249,7 +249,7 @@ int respond(client_ctx_t *ctx) {
|
||||
if (http_get_header_field(&res->hdr, "Accept-Ranges") == NULL) {
|
||||
http_add_header_field(&res->hdr, "Accept-Ranges", "none");
|
||||
}
|
||||
if (!ctx->use_fastcgi && ctx->file == NULL && ctx->msg_buf == NULL) {
|
||||
if (!ctx->use_fastcgi && ctx->file == NULL && ctx->msg_buf == NULL && res->status->code != 304) {
|
||||
http_remove_header_field(&res->hdr, "Date", HTTP_REMOVE_ALL);
|
||||
http_remove_header_field(&res->hdr, "Server", HTTP_REMOVE_ALL);
|
||||
http_remove_header_field(&res->hdr, "Cache-Control", HTTP_REMOVE_ALL);
|
||||
|
Reference in New Issue
Block a user