rack-proxy is a sharp tool for proxying in ruby.
But I'm currently stuck in using it.
One of our 3rd party service endpoints needs a header injection in the proxy and it looks like:
client_id
And I found it's being changed to client-id
by proxy in the final request.
What could be the solution?
Any help would be appreciated!
Asked
Active
Viewed 179 times
0

crazyoptimist
- 125
- 1
- 14
-
1Might be interesting in this context: https://stackoverflow.com/questions/22856136/why-do-http-servers-forbid-underscores-in-http-header-names – spickermann Dec 19 '20 at 06:43
-
Thanks, I've checked it before posting the question but didn't find relevant solution. Would be appreciated if you add more detailed explanation about it. By the way the replacement in the rack-proxy is happening [here](https://github.com/ncr/rack-proxy/blob/bee97d2b25a8c6611b4dccba2bb62288f5ac3596/lib/rack/proxy.rb#L37) One workaround is monkey patching. I can also create a PR for removing the replacement it but not sure it would be accepted. – crazyoptimist Dec 19 '20 at 10:07
-
1I understand the question and its answer in the way that (although allow) it is not recommended to use underscores in headers and in fact many well-known apps (like Nginx and Apache) do not support them. That said: Ask the provider of the API to support dashes too because that is the way to go. – spickermann Dec 19 '20 at 10:46
-
1Very reasonable opinion, I agree on that! – crazyoptimist Dec 19 '20 at 10:47
-
1Rack is based on CGI's (somewhat historic) model, [which means that underscores are ambiguous](https://stackoverflow.com/a/22856867/4025095) since internally dashes in header names are replaced with underscores (see [the Rack specifications](https://github.com/rack/rack/blob/master/SPEC.rdoc))... in other words, the only way would be to avoid Rack or monkey patch a specific exception. – Myst Dec 22 '20 at 00:35
-
Currently going for monkey patching. But just curious, where is such replacement specification in your reference link "the Rack specifications"? I tried and couldn't find anything. Obviously the replacement is happening in rack-proxy code [here](https://github.com/ncr/rack-proxy/blob/bee97d2b25a8c6611b4dccba2bb62288f5ac3596/lib/rack/proxy.rb#L37) and we've already overloaded it. – crazyoptimist Dec 22 '20 at 04:19
-
Oh, got it now, thanks for advice, it was [here](https://tools.ietf.org/html/rfc3875#section-4.1.18), you are right @Myst – crazyoptimist Dec 22 '20 at 04:26