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

Don't alter Content-Type in Request if user explicitly sets it (#184) #886

Closed
wants to merge 1 commit into from

Conversation

EPNW-Eric
Copy link

I'm using this library and came across a very frustrating bug, see #184.
The core problem is, that this library alters the Content-Type header I (as a developer) explicitly set.
This is dangerous behaviour and should be removed.

@kevmoo
Copy link
Member

kevmoo commented Mar 3, 2023

CC @brianquinlan @devoncarew – let's be careful with any change here. This has been "the way it is" for a very long time.

@EPNW-Eric
Copy link
Author

CC @brianquinlan @devoncarew – let's be careful with any change here. This has been "the way it is" for a very long time.

Yes, it's been this way for years, despite the original issue beeing labeld as type-bug...
An other idee for solving this without breaking compability would be introducing a new, optional bool appendCharsetIfNotSet (defaulting to true) to the Request constructor and change

} else if (!contentType.parameters.containsKey('charset')) {

to something like

  } else if (!contentType.parameters.containsKey('charset') && appendCharsetIfNotSet) {

@DHMG-Git
Copy link

DHMG-Git commented Mar 3, 2024

CC @brianquinlan @devoncarew – let's be careful with any change here. This has been "the way it is" for a very long time.

Yes, it's been this way for years, despite the original issue beeing labeld as type-bug... An other idee for solving this without breaking compability would be introducing a new, optional bool appendCharsetIfNotSet (defaulting to true) to the Request constructor and change

} else if (!contentType.parameters.containsKey('charset')) {

to something like

  } else if (!contentType.parameters.containsKey('charset') && appendCharsetIfNotSet) {

I completely agree. This exact behaviour makes it impossible to use this package for API calls to a filemaker server because the server rejects the sneakily added extra header.
This is especially annoying if you are using an app like FlutterFlow, where you have no influence over the default behaviour of packages, which makes it necessary to write everything in custom code, which negates the whole purpose of using such a tool in the first place.
Please fix this issue or add an optional property that disables this behaviour like suggested by EPNW-Eric.

@gnprice
Copy link

gnprice commented Mar 5, 2024

It turns out that the automatic setting of a charset in Content-Type can be avoided by not setting the body property, and instead setting bodyBytes.

This was observed last year in the #184 thread, and documented in #1014. See docs:
https://pub.dev/documentation/http/latest/http/Request/body.html

So that seems like a pretty reasonable way to avoid setting a charset.

And conversely, it seems pretty appropriate that if you do choose to set body rather than bodyBytes, then that would set a charset in the Content-Type header. After all, the one other thing that the body setter does apart from set bodyBytes is that it uses the request's encoding to turn the given string into bytes. So if the bytes you're putting in the request truly aren't encoded in that charset, then using the body setter doesn't make a lot of sense conceptually anyway.

Given that, I think it'd be appropriate to close this issue as resolved (by the documentation PR #1014), just as #184 was resolved.

@kevmoo
Copy link
Member

kevmoo commented Mar 5, 2024

See notes from @gnprice – feel free to push back

@kevmoo kevmoo closed this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants