CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
MIT License
134 stars 67 forks source link

BugFix: duplicate GET parameters. (Causes invalid URL format) #13

Closed juani15151 closed 4 years ago

juani15151 commented 4 years ago

Sumary

Doing client.get(".../api?param=value") ends up doing a request to ".../api?param=value?param=value"

About the fix

The problem seems to happen because RequestData.fromHttpRequest(Request request) method parsed the query parameters and put them on 'params', but when recreating a request at toHttpRequest() method it appended the parameters to the url again.

This fix splits the URL at fromHttpRequest method removing the queryParams, so Now data['url'] contains the URL without queryParams. (wich are still accesible through data['params']).

Note: this fix was tested for this specific use case only.

Fix for older versions

This can be fixed directly in the interceptor code by removing the queryParams from the URL. Simply add: data['url'] = data['url'].split("?")[0]; at the beggining of the interceptRequest method.

CodingAleCR commented 4 years ago

Hi. I was wondering if anyone was having the same issue. I started working on a fix a little back, it will also add testing to the plugin so I can find this issues beforehand. Nice catch as well, will work on merging + releasing this week. Nice job!

CodingAleCR commented 4 years ago

This should be fixed as of #15 and the release 0.2.0 of the library.