Skip to content

Commit 42fa822

Browse files
committed
Move to own function
1 parent 7ee7c4e commit 42fa822

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

cgi/mapcache.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,43 @@ static void load_config(mapcache_context *ctx, char *filename)
242242

243243
}
244244

245+
static void set_headers(mapcache_context* ctx, char** env)
246+
{
247+
// add all environ settings including HTTP headers to
248+
// a ctx->headers_in apr_table_t
249+
250+
char* key, * val, * kvp, * pair;
251+
int i;
252+
int num_env_var;
253+
254+
num_env_var = 0;
255+
while (env[num_env_var] != NULL)
256+
num_env_var++;
257+
258+
apr_table_t* headers;
259+
headers = apr_table_make(ctx->pool, num_env_var);
260+
261+
for (i = 0; env[i] != NULL; i++) {
262+
kvp = env[i];
263+
264+
// convert HTTP header keys from the form HTTP_MY_HEADER to MY-HEADER
265+
key = apr_strtok(kvp, "=", &pair);
266+
key = mapcache_util_str_replace(ctx->pool, key, "HTTP_", "");
267+
key = mapcache_util_str_replace(ctx->pool, key, "_", "-");
268+
// key = str_replace_all(ctx->pool, key, "_", "-");
269+
val = apr_strtok(NULL, "=", &pair);
270+
271+
if (val != NULL) {
272+
apr_table_addn(headers, key, val);
273+
}
274+
else {
275+
apr_table_addn(headers, key, "");
276+
}
277+
}
278+
279+
ctx->headers_in = headers;
280+
}
281+
245282
int main(int argc, const char **argv)
246283
{
247284
mapcache_context_fcgi* globalctx;
@@ -311,40 +348,7 @@ int main(int argc, const char **argv)
311348
goto cleanup;
312349
}
313350

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;
351+
set_headers(ctx, environ);
348352

349353
http_response = NULL;
350354
if(request->type == MAPCACHE_REQUEST_GET_CAPABILITIES) {

0 commit comments

Comments
 (0)