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

Unable to override Content-Type header #630

Open
ashitaprasad opened this issue Mar 2, 2025 · 8 comments · May be fixed by #631
Open

Unable to override Content-Type header #630

ashitaprasad opened this issue Mar 2, 2025 · 8 comments · May be fixed by #631
Labels

Comments

@ashitaprasad
Copy link
Member

Describe the bug/problem

Create a new POST request as shown below with JSON body

Image

If you do not specify any content-type in header, the client automatically sets it to application/json; charset=utf-8.

In the headers, you can specify the Content-Type as application/json to override the default and send request. When you inspect headers in response pane you can observe that the Request header that was sent for Content-Type was application/json; charset=utf-8 instead of application/json

Image

`charset=utf-8' is automatically added into 'Content-Type', and we are unable to remove it as for some APIs, this header string can cause rejection.

Similarly, if you set text/csv as Content-Type in Request and send the response. Again charset=utf-8' is being automatically added by http` library.

Image

The objective is that user should have full control over the Content-Type header that is being sent to the server.

Relevant issues:

@AffanShaikhsurab
Copy link
Contributor

i was able ot reproduce the issue : we should allow the user to have a total control over the content type . I will look into it and see how we can solve this

@AffanShaikhsurab
Copy link
Contributor

@ashitaprasad should we also allow the user to choose the encoding ?

@Jaishree2310
Copy link

@AffanShaikhsurab Are you working on this issue ?

I wanted to work on this if needed can both work together?

@AffanShaikhsurab
Copy link
Contributor

Hi @Jaishree2310,

I've already created a pull request (#631) to address this issue. However, if you have any suggestions or improvements, feel free to review the PR and share your thoughts. I'd be happy to collaborate or make any necessary refinements.

@ashitaprasad
Copy link
Member Author

ashitaprasad commented Mar 2, 2025

@ashitaprasad should we also allow the user to choose the encoding ?

@AffanShaikhsurab The default encoding should be utf-8, if the user specifies a particular encoding using header field Content-Type like application/json; charset=utf-16 or application/json; charset=iso-8859-1 or application/json; charset=us-ascii. Then the body must be encoded using the specified encoding.
https://api.flutter.dev/flutter/dart-convert/Encoding/getByName.html

@AffanShaikhsurab
Copy link
Contributor

AffanShaikhsurab commented Mar 3, 2025

@ashitaprasad Thanks for clarifying , the current implementation in the pr satisfies the above functionality

Image

@ashitaprasad
Copy link
Member Author

@ashitaprasad Thanks for clarifying , the current implementation in the pr satisfies the above functionality

Image

No @AffanShaikhsurab it doesn't. The Request header for Content-Type being sent is application/json; charset=utf-16 but the actual body is being encoded in utf-8

@AffanShaikhsurab
Copy link
Contributor

@ashitaprasad Apologies for the oversight! I've updated it to support multiple encoding types. If you have any further suggestions, I'd be happy to implement them!

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 a pull request may close this issue.

3 participants