Skip to content

Do not include custom request in the URL#103

Open
jesusbotella wants to merge 2 commits intot3chnoboy:1.0from
jesusbotella:delete-request-property-from-query
Open

Do not include custom request in the URL#103
jesusbotella wants to merge 2 commits intot3chnoboy:1.0from
jesusbotella:delete-request-property-from-query

Conversation

@jesusbotella
Copy link

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 :)

@masterT masterT removed their request for review February 8, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant