Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

betawait
Copy link

@betawait betawait commented Feb 9, 2025

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:

  • The pull request only addresses one issue or adds one feature.
  • [] The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

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.

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.
@betawait betawait force-pushed the bugfix/bug-remove-content-type-in-post-with-no-body branch from 44927fa to fe2b03e Compare February 9, 2025 12:41
@betawait betawait changed the title Fix: Allow empty Content-Type when no body #1693 Fix: Allow empty Content-Type when no body (#1693) Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant