Skip to content

Commit

Permalink
Allow to provide custom Cache-Control header values (fixes #322)
Browse files Browse the repository at this point in the history
  • Loading branch information
marisn committed Jan 22, 2024
1 parent 2ac1a61 commit 83c0933
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/mapcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,14 @@ struct mapcache_tileset {
*/
int auto_expire;

/**
* Cache-Control directives to be set for a TMS response
*
* complements expiration set by the #expires parameter.
* \sa expires
*/
const char *cache_control;

int read_only;
int subdimension_read_only;

Expand Down
5 changes: 5 additions & 0 deletions lib/configuration_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,11 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
}
}

tileset->cache_control = NULL;
if ((cur_node = ezxml_child(node,"cache-control")) != NULL) {
tileset->cache_control = apr_pstrdup(ctx->pool, cur_node->txt);
}

if ((cur_node = ezxml_child(node,"metabuffer")) != NULL) {
char *endptr;
tileset->metabuffer = (int)strtol(cur_node->txt,&endptr,10);
Expand Down
13 changes: 12 additions & 1 deletion lib/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,22 @@ mapcache_http_response *mapcache_core_get_tile(mapcache_context *ctx, mapcache_r
apr_time_t now = apr_time_now();
apr_time_t additional = apr_time_from_sec(expires);
apr_time_t texpires = now + additional;
apr_table_set(response->headers, "Cache-Control",apr_psprintf(ctx->pool, "max-age=%d", expires));
timestr = apr_palloc(ctx->pool, APR_RFC822_DATE_LEN);
apr_rfc822_date(timestr, texpires);
apr_table_setn(response->headers, "Expires", timestr);
}
if (expires || req_tile->tiles[0]->tileset->cache_control) {
apr_table_set(
response->headers, "Cache-Control",
apr_pstrcat(
ctx->pool,
expires ? apr_psprintf(ctx->pool, "max-age=%d", expires) : "",
expires && req_tile->tiles[0]->tileset->cache_control ? ", " : "",
req_tile->tiles[0]->tileset->cache_control
? req_tile->tiles[0]->tileset->cache_control
: "",
NULL));
}

return response;
}
Expand Down

0 comments on commit 83c0933

Please sign in to comment.