clusterfk / chaos-proxy

ClusterFk Chaos Proxy is an unreliable HTTP proxy you can rely on; a lightweight tool designed for chaos testing of microservices.
http://clusterfk.it
GNU General Public License v3.0
97 stars 11 forks source link

[#3] Fix requests with encoded URLs #6

Closed piomar123 closed 4 years ago

piomar123 commented 4 years ago

It looks like servlet.getServletPath() returns a decoded path, even though the request contains an encoded one. Then, the request is rewritten by ProxyTargetUrlBuilder to create the request path for destination server. We could use UriComponentsBuilder to encode the path back but it just seems safer to use getRequestURI() which returns the original requested encoded URI that can be redirected into the destination server. And this solution has been proposed in this PR.

Additionally, a few tests have been refactored to use the real ProxyTargetUrlBuilder logic instead of mocking it.

More literature about the URI encoding in Spring: https://stackoverflow.com/questions/966077/java-reading-undecoded-url-from-servlet https://stackoverflow.com/questions/4931323/whats-the-difference-between-getrequesturi-and-getpathinfo-methods-in-httpservl

piomar123 commented 4 years ago

Any comments/thoughts on that solution?

AndyMacDroo commented 4 years ago

Sorry for the delay in responding. Great contribution - thanks :+1: