Do not include custom request in the URL #103
Open
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.
Hello everyone!
I send this PR to avoid encoding the request custom function (if any) into the URL parameters.
I have seen that if we include any custom request function, it will end up being encoded in the URL like this:
&Request=function%20request%28uri%2C%20options%2C%20callback%29%20%7B%0A%20%20if%20%28typeof%20uri%20%3D%3D%3D%20%27undefined%27%29%20%7B%0A%20%20%20%20throw%20new%20Error%28%27undefined%20is%20not%20a%20valid%20uri%20or%20options%20object.%27%29%0A%20%20%7D%0A%0A%20%20var%20params%20%3D%20initParams%28uri%2C%20options%2C%20callback%29%0A%0A%20%20if%20%28params.method%20%3D%3D%3D%20%27HEAD%27%20%26%26%20paramsHaveRequestBody%28params%29%29%20%7B%0A%20%20%20%20throw%20new%20Error%28%27HTTP%20HEAD%20requests%20MUST%20NOT%20include%20a%20request%20body.%27%29%0A%20%20%7D%0A%0A%20%20return%20new%20request.Request%28params%29%0A%7D
I saw that in the master branch there were a delete statement to remove it out from query parameters, but it is gone right now.
Adding a delete statement to delete an object property is not as performant as setting it to
undefined
. So what I did is to set it to undefined, and then check if each query parameter is not undefined before assigning it to URL parameters, encoding only the needed parameters in the URL.I hope there is no major issue with it. If you have any concern or improvement about it, please tell me :)