Fix: Allow empty Content-Type when no body (#1693) #3973
+65
−29
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.
By default Axios will set the Content-Type for POST/PUT/PATCH requests to "application/x-www-form-urlencoded" if the Content-Type header is not specified.
This explicitly sets the content type to "false" when there the body mode is set to "none", and the user has not set an explicit content type themselves. Setting the content type to false directs Axios not to send a Content-Type header.
Description
This PR fixes an issue where an unwanted Content-Type header would be added to a POST request with body mode set to "none". Axios adds "application/x-www-form-urlencoded" as the default Content-Type for POST/PUT/PATCH requests, unless the content type is explicitly set to 'false'.
If content-type is explicitly set by a user then that will still be preserved.
The interpolate-vars.js file had to be modified to handle content-type being set to 'false', as it was always expecting a string, and creating an empty string otherwise.
This is my first time in the bruno codebase, so I'm not confident I've thought about other side-effects this could have. I'm also not sure about bruno-cli. I would welcome any advice on other places to check.
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.