|
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,6 +162,16 @@ static void fcgi_write_response(mapcache_context_fcgi *ctx, mapcache_http_respon |
158 | 162 | } |
159 | 163 | } |
160 | 164 |
|
| 165 | +// Replace all occurrences of substr in string |
| 166 | +char* str_replace_all(apr_pool_t* pool, const char* string, |
| 167 | + const char* substr, const char* replacement) |
| 168 | +{ |
| 169 | + char* replaced = apr_pstrdup(pool, string); |
| 170 | + while (strstr(replaced, substr)) { |
| 171 | + replaced = mapcache_util_str_replace(pool, string, substr, replacement); |
| 172 | + } |
| 173 | + return replaced; |
| 174 | +} |
161 | 175 |
|
162 | 176 | apr_time_t mtime; |
163 | 177 | char *conffile; |
@@ -297,6 +311,41 @@ int main(int argc, const char **argv) |
297 | 311 | goto cleanup; |
298 | 312 | } |
299 | 313 |
|
| 314 | + // add all environ settings including HTTP headers to |
| 315 | + // a ctx->headers_in apr_table_t |
| 316 | + |
| 317 | + int num_env_var = 0; |
| 318 | + char** env = environ; |
| 319 | + |
| 320 | + while (env[num_env_var] != NULL) |
| 321 | + num_env_var++; |
| 322 | + |
| 323 | + apr_table_t* headers; |
| 324 | + headers = apr_table_make(ctx->pool, num_env_var); |
| 325 | + |
| 326 | + char *key, *val, * kvp, *pair; |
| 327 | + int i; |
| 328 | + |
| 329 | + for (i = 0; env[i] != NULL; i++) { |
| 330 | + kvp = env[i]; |
| 331 | + |
| 332 | + // convert HTTP header keys from the form HTTP_MY_HEADER to MY-HEADER |
| 333 | + key = apr_strtok(kvp, "=", &pair); |
| 334 | + key = mapcache_util_str_replace(ctx->pool, key, "HTTP_", ""); |
| 335 | + key = mapcache_util_str_replace(ctx->pool, key, "_", "-"); |
| 336 | + // key = str_replace_all(ctx->pool, key, "_", "-"); |
| 337 | + val = apr_strtok(NULL, "=", &pair); |
| 338 | + |
| 339 | + if (val != NULL) { |
| 340 | + apr_table_addn(headers, key, val); |
| 341 | + } |
| 342 | + else { |
| 343 | + apr_table_addn(headers, key, ""); |
| 344 | + } |
| 345 | + } |
| 346 | + |
| 347 | + ctx->headers_in = headers; |
| 348 | + |
300 | 349 | http_response = NULL; |
301 | 350 | if(request->type == MAPCACHE_REQUEST_GET_CAPABILITIES) { |
302 | 351 | mapcache_request_get_capabilities *req = (mapcache_request_get_capabilities*)request; |
|
0 commit comments