Skip to content

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

Conversation

betawait
Copy link
Contributor

@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.

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

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

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

 

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.

@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
@betawait betawait force-pushed the bugfix/bug-remove-content-type-in-post-with-no-body branch from fe2b03e to 653853a Compare February 13, 2025 22:53
@pull-request-size pull-request-size bot added size/L and removed size/M labels Feb 13, 2025
@betawait
Copy link
Contributor Author

Updated to fix conflict.

@anusree-bruno
Copy link
Collaborator

Fixes
#826
#2323
#1693

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 653853a to 1d12beb Compare May 14, 2025 22:53
@betawait
Copy link
Contributor Author

Fixed conflicts.

@lohit-bruno lohit-bruno merged commit fab9d00 into usebruno:main Jun 27, 2025
@frokev
Copy link

frokev commented Jun 30, 2025

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:
Pre-Request Script Error contentType.includes is not a function

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 😊

@Its-treason
Copy link
Member

The fix seems to just have set the Content-Type header to undefined. 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 😑

I think this is kinda like #4428 but the Header is actually sent as undefined.

@frokev
Copy link

frokev commented Jun 30, 2025

The fix seems to just have set the Content-Type header to undefined. 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 😑

I think this is kinda like #4428 but the Header is actually sent as undefined.

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.

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.

7 participants