Skip to content

Commit eacbe93

Browse files
committed
Allow forwarding of client headers to source
1 parent e95ddc3 commit eacbe93

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

apache/mod_mapcache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static int mod_mapcache_request_handler(request_rec *r)
343343
apache_ctx = apache_request_context_create(r);
344344
global_ctx = (mapcache_context*)apache_ctx;
345345
global_ctx->supports_redirects = 1;
346+
global_ctx->headers_in = r->headers_in;
346347

347348
params = mapcache_http_parse_param_string(global_ctx, r->args);
348349

include/mapcache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ struct mapcache_context {
249249
mapcache_service *service;
250250
apr_table_t *exceptions;
251251
int supports_redirects;
252+
apr_table_t *headers_in;
252253
};
253254

254255
void mapcache_context_init(mapcache_context *ctx);

lib/http.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ size_t _mapcache_curl_header_callback( void *ptr, size_t size, size_t nmemb, vo
7373
return size*nmemb;
7474
}
7575

76+
/*update val replacing {foo_header} with the Value of foo_header from the orginal request */
77+
static void _header_replace_str(mapcache_context *ctx, apr_table_t *headers, char **val) {
78+
char *value = *val;
79+
char *start_tag, *end_tag;
80+
start_tag = strchr(value,'{');
81+
while(start_tag) {
82+
*start_tag=0;
83+
end_tag = strchr(start_tag+1,'}');
84+
if(end_tag) {
85+
const char *header_value;
86+
*end_tag=0;
87+
header_value = apr_table_get(headers,start_tag+1);
88+
if(header_value) {
89+
value = apr_pstrcat(ctx->pool,value,header_value,end_tag+1,NULL);
90+
}
91+
*end_tag='}';
92+
}
93+
*start_tag='{';
94+
start_tag = strchr(value,'{');
95+
}
96+
*val = value;
97+
}
98+
7699
void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcache_buffer *data, apr_table_t *headers, long *http_code)
77100
{
78101
CURL *curl_handle;
@@ -115,7 +138,11 @@ void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcach
115138
apr_table_entry_t *elts = (apr_table_entry_t *) array->elts;
116139
int i;
117140
for (i = 0; i < array->nelts; i++) {
118-
curl_headers = curl_slist_append(curl_headers, apr_pstrcat(ctx->pool,elts[i].key,": ",elts[i].val,NULL));
141+
char *val = elts[i].val;
142+
if(strchr(val,'{') && ctx->headers_in) {
143+
_header_replace_str(ctx,ctx->headers_in,&val);
144+
}
145+
curl_headers = curl_slist_append(curl_headers, apr_pstrcat(ctx->pool,elts[i].key,": ",val,NULL));
119146
}
120147
}
121148
if(!req->headers || !apr_table_get(req->headers,"User-Agent")) {

lib/util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ void mapcache_context_init(mapcache_context *ctx)
290290
ctx->clear_errors = _mapcache_context_clear_error_default;
291291
ctx->pop_errors = _mapcache_context_pop_errors;
292292
ctx->push_errors = _mapcache_context_push_errors;
293+
ctx->headers_in = NULL;
293294
}
294295

295296
void mapcache_context_copy(mapcache_context *src, mapcache_context *dst)
@@ -314,6 +315,7 @@ void mapcache_context_copy(mapcache_context *src, mapcache_context *dst)
314315
dst->pop_errors = src->pop_errors;
315316
dst->push_errors = src->push_errors;
316317
dst->connection_pool = src->connection_pool;
318+
dst->headers_in = src->headers_in;
317319
}
318320

319321
char* mapcache_util_get_tile_dimkey(mapcache_context *ctx, mapcache_tile *tile, char* sanitized_chars, char *sanitize_to)

0 commit comments

Comments
 (0)