|
39 | 39 | #include <fcgi_stdio.h> |
40 | 40 | #endif |
41 | 41 |
|
| 42 | +#ifndef WIN32 |
| 43 | +extern char** environ; |
| 44 | +#endif |
| 45 | + |
42 | 46 | typedef struct mapcache_context_fcgi mapcache_context_fcgi; |
43 | 47 | typedef struct mapcache_context_fcgi_request mapcache_context_fcgi_request; |
44 | 48 |
|
@@ -158,7 +162,6 @@ static void fcgi_write_response(mapcache_context_fcgi *ctx, mapcache_http_respon |
158 | 162 | } |
159 | 163 | } |
160 | 164 |
|
161 | | - |
162 | 165 | apr_time_t mtime; |
163 | 166 | char *conffile; |
164 | 167 |
|
@@ -228,6 +231,43 @@ static void load_config(mapcache_context *ctx, char *filename) |
228 | 231 |
|
229 | 232 | } |
230 | 233 |
|
| 234 | +static void set_headers(mapcache_context* ctx, char** env) |
| 235 | +{ |
| 236 | + // add all environ settings including HTTP headers to |
| 237 | + // a ctx->headers_in apr_table_t |
| 238 | + |
| 239 | + char * key, * val, * kvp, * pair; |
| 240 | + int i; |
| 241 | + int num_env_var; |
| 242 | + apr_table_t* headers; |
| 243 | + |
| 244 | + num_env_var = 0; |
| 245 | + while (env[num_env_var] != NULL) |
| 246 | + num_env_var++; |
| 247 | + |
| 248 | + headers = apr_table_make(ctx->pool, num_env_var); |
| 249 | + |
| 250 | + for (i = 0; env[i] != NULL; i++) { |
| 251 | + kvp = apr_pstrdup(ctx->pool, env[i]); |
| 252 | + |
| 253 | + // convert HTTP header keys from the form HTTP_MY_HEADER to MY-HEADER |
| 254 | + key = apr_strtok(kvp, "=", &pair); |
| 255 | + key = mapcache_util_str_replace(ctx->pool, key, "HTTP_", ""); |
| 256 | + key = mapcache_util_str_replace_all(ctx->pool, key, "_", "-"); |
| 257 | + |
| 258 | + val = apr_strtok(NULL, "=", &pair); |
| 259 | + |
| 260 | + if (val != NULL) { |
| 261 | + apr_table_addn(headers, key, val); |
| 262 | + } |
| 263 | + else { |
| 264 | + apr_table_addn(headers, key, ""); |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + ctx->headers_in = headers; |
| 269 | +} |
| 270 | + |
231 | 271 | int main(int argc, const char **argv) |
232 | 272 | { |
233 | 273 | mapcache_context_fcgi* globalctx; |
@@ -297,6 +337,8 @@ int main(int argc, const char **argv) |
297 | 337 | goto cleanup; |
298 | 338 | } |
299 | 339 |
|
| 340 | + set_headers(ctx, environ); |
| 341 | + |
300 | 342 | http_response = NULL; |
301 | 343 | if(request->type == MAPCACHE_REQUEST_GET_CAPABILITIES) { |
302 | 344 | mapcache_request_get_capabilities *req = (mapcache_request_get_capabilities*)request; |
|
0 commit comments