foundeo / bolthttp

A HTTP Client for CFML
Apache License 2.0
30 stars 6 forks source link

Issues with mod_cfml on first request #7

Open dswitzer opened 2 years ago

dswitzer commented 2 years ago

We've noticed a problem with bolthttp when a request is made to a server running mod_cfml to create dynamic Tomcat contexts.

The issue is that mod_cfml will issue a redirect (hopefully a 307) to force the client to retry to request.

You can work around this by enabling redirects on a request, but in our case we explicitly are not following redirects because a 301 or 302 is a sign of a problem.

It would appear this issue can be solved in Apache HttpClient by implementing a redirect strategy. I'm wondering if it would make sense to add support for configuring BoltHTTP to only follow specific redirect commands or at least potentially always honor a 307 redirect, since this seems to be specifically for these kinds of operations (where an HTTP request must be retried).

pfreitag commented 2 years ago

I think it would probably be best left to the application code to handle the retry, as I don't think it would be clear to the developer if it redirected automatically on certain status codes and not for others. There are cases where I write code that I don't want to redirect in any circumstance like you are.

If something was builtin to bolt, and it was done with an option that was off by default I'd be ok with that approach.

dswitzer commented 2 years ago

A potential approach to solving this issue would be to refactor the redirect configuration option to accept the following:

Value Description
true Enabled redirects
false Disable redirects
List of HTTP status code Only redirect on the specific status codes.

So if a list is supplied, we'd trigger a custom redirect strategy that would only redirect on those specific status codes.