Skip to content

Conversation

@geographika
Copy link
Member

@geographika geographika commented Sep 2, 2021

Initial attempt at resolving #256 and providing the same HTTP header forwarding functionality as the Apache module.
Tested and working on IIS as a FastCGI module.

For each request the environ is looped through (note this is the FastCGI environment rather than the system environment (see MapServer discussions here.

There seems to be no way to know which server variables are HTTP headers and what are other variables.

HTTP headers are saved as server variables in the format "HTTP_MY_HEADER", but are expected to be available as "MY-HEADER". The code attempts to set this. I took a copy of the str_replace_all function from:

char * str_replace_all(apr_pool_t *pool, const char *string,
(if it works this function could perhaps be moved to the util.c file?).

This was an attempt to replace all instances of "_" with "-". However it seemed to send the server into an infinite loop.

I tried to stay with the approach used in the rest of MapCache, mainly by searching and copying, so code reviews very welcome..!

@geographika
Copy link
Member Author

Thanks for the review @jbo-ads.
I was running into server crashes (on every other request) when directly copying the environment, but these were resolved by creating a copy of the KEY=VALUE pair when looping through them, prior to modifications:

kvp = apr_pstrdup(ctx->pool, env[i]);

This was more by trial and error so let me know if there is a better way.

I've tested in IIS, and with server variables with multiple underscored e.g. HTTP_PART1_PART2 and these are passed to the back-end server as PART1-PART2 headers - the same as the Apache module.

The code does copy all environ variables, not just headers, but I don't see any way around this as custom headers could use any name.

@geographika geographika marked this pull request as ready for review September 2, 2021 15:31
@jbo-ads jbo-ads merged commit 47d2757 into MapServer:main Sep 2, 2021
@jbo-ads
Copy link
Member

jbo-ads commented Sep 2, 2021

Thanks @geographika for this enhancement!

@geographika
Copy link
Member Author

Thanks again for taking the time to review @jbo-ads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants