-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix: Allow empty Content-Type when no body (#1693) #3973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Allow empty Content-Type when no body (#1693) #3973
Conversation
44927fa
to
fe2b03e
Compare
fe2b03e
to
653853a
Compare
Updated to fix conflict. |
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.
653853a
to
1d12beb
Compare
Fixed conflicts. |
The Content-Type header is set to undefined when not included. It needs to be removed from the header collection. If you look at the Timeline you see Content-Type is still included as undefined, when you have not included it as a header at all for a GET request. A third-party API we use does not allow this, so we can't use Bruno 😑 In pre-request script, if you try to set the Content-Type header to null, you'll get this error: We should be able to control which headers are automatically applied by Bruno, such as User-Agent as well. If not, it quickly introduces issues when testing against APIs that doesn't handle edge-cases to a high standard. Edit: I'm at version 2.6.1, and I see this deviates a lot from the issue, so I created a new one, #5012 😊 |
I think this is kinda like #4428 but the Header is actually sent as |
It does seem like it mentions it. But I'm not sure the issue conveyed the issue as well. I'll leave mine open #5012 I guess. |
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.
Jira
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.
The original issue could be seen here:

After the fix, the content-type header is not reflected back:

Note you are still able to explicitly add a contenty-type header when there is no body:

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.