Skip to content

Commit 63a8908

Browse files
marisnjmckenna
authored andcommitted
Allow to provide custom Cache-Control header values (fixes #322) (#329)
1 parent c01c6d3 commit 63a8908

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

include/mapcache.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,14 @@ struct mapcache_tileset {
11991199
*/
12001200
int auto_expire;
12011201

1202+
/**
1203+
* Cache-Control directives to be set for a tiled response (MAPCACHE_REQUEST_GET_TILE)
1204+
*
1205+
* complements expiration set by the #expires parameter.
1206+
* \sa expires
1207+
*/
1208+
const char *cache_control;
1209+
12021210
int read_only;
12031211
int subdimension_read_only;
12041212

lib/configuration_xml.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,11 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
11631163
}
11641164
}
11651165

1166+
tileset->cache_control = NULL;
1167+
if ((cur_node = ezxml_child(node,"cache-control")) != NULL) {
1168+
tileset->cache_control = apr_pstrdup(ctx->pool, cur_node->txt);
1169+
}
1170+
11661171
if ((cur_node = ezxml_child(node,"metabuffer")) != NULL) {
11671172
char *endptr;
11681173
tileset->metabuffer = (int)strtol(cur_node->txt,&endptr,10);

lib/core.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,22 @@ mapcache_http_response *mapcache_core_get_tile(mapcache_context *ctx, mapcache_r
346346
apr_time_t now = apr_time_now();
347347
apr_time_t additional = apr_time_from_sec(expires);
348348
apr_time_t texpires = now + additional;
349-
apr_table_set(response->headers, "Cache-Control",apr_psprintf(ctx->pool, "max-age=%d", expires));
350349
timestr = apr_palloc(ctx->pool, APR_RFC822_DATE_LEN);
351350
apr_rfc822_date(timestr, texpires);
352351
apr_table_setn(response->headers, "Expires", timestr);
353352
}
353+
if (expires || req_tile->tiles[0]->tileset->cache_control) {
354+
apr_table_set(
355+
response->headers, "Cache-Control",
356+
apr_pstrcat(
357+
ctx->pool,
358+
expires ? apr_psprintf(ctx->pool, "max-age=%d", expires) : "",
359+
expires && req_tile->tiles[0]->tileset->cache_control ? ", " : "",
360+
req_tile->tiles[0]->tileset->cache_control
361+
? req_tile->tiles[0]->tileset->cache_control
362+
: "",
363+
NULL));
364+
}
354365

355366
return response;
356367
}

0 commit comments

Comments
 (0)