bugfix proxy and rewrite, updated test with actual call settings #1630
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: Proxy and Rewrite Middleware don't set URL appropriately in tests and this causes different behavior when running tests vs when proxy and rewrite middleware are used in real server mode.
We should use url Parse method instead.
Check how path, raw path is set when using URL.Parse in this playground example. This is how url path and raw path is set when running echo server and invoking API endpoints.
After updating tests, was able to find a bug in proxy and rewrite and was able to fix it (and made sure it passes in real scenario calls as well).
Also, refactored some common code that's shared between proxy with rewrite rules and rewrite middleware rules. This also fixed one other bug e.g. the regex rules for rewrite is different from proxy regex rules when they should be same (rewrite regex rules works as expected).
After refactoring and using common function the below test works in proxy and rewrite (in current master code, proxy test for below scenario would fail):