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
HttpClient sends the wrong Accept header #28915
Comments
@the-avid-engineer could you please provide a minimal reproduction? |
Yes I will do that |
@the-avid-engineer awesome! when you have it just let me know and I will check it out. |
@m-henderson Well I've found this issue 5 months after the last comment and figured I'd make the repro myself: https://stackblitz.com/edit/angular-issue-repro2-fjrew5 here you go Just open dev tools and you can see that the GET has Which is a lie. It will not, in fact, accept anything other than application/json. If HttpClient will attempt to parse the response as JSON by default, then it should not send anything other than |
@daleclements thanks for making a repro |
I've been a bit busy, and haven't had any time to reproduce it in the scenario I described... but here's a bit more info. I have several endpoints running on .NET Core / MVC which return strings. Given an endpoint that returns a string, and a request with two acceptable content types ( I've overridden my calls to always only send |
Apparently I spoke too soon - while We should at a minimum evaluate whether this is necessary or at all desirable. Technically though, it would be a breaking change, so it would have to happen in Angular v11. |
this bug hasn't been fixed. I am working on Angular v10.0.7. dont work here:
work well here:
httpClient.get<HttpResponse>(url) and httpClient.get<HttpResponse>(url) should be implemented in the future |
@hungnguyenmanh82 It's not a bug. It works as designed and was many times explained why this way has been chosen. Btw, |
BTW, adding this header also (currently) breaks HTTP2 preloading. See #34899 (comment) for details. |
IMO there should be at least a way to opt-out of this behavior |
The It might be safe these days to just default to However, that would still not solve the problem with preloading captured in #34899 (comment). Defaulting to nothing at all might be too breaky though... so maybe the best path forward is to:
Thoughts? |
Not sure how breaky it would be to change the default to But providing a way to opt out of setting the header or (even better) having a way to set the default/fallback headers would be a non-breaking and quite flexible, so +1 from me. |
I think a breaking change for v12 to change the default would be fine, if we can make it easy to update the default without having to change all requests. |
Hello from the future! Any plans to change this behavior? Also, is #48505 a duplicate? |
🐞 bug report
Affected Package
@angular/common/http
Is this a regression?
Not sure
Description
The
get<T>
method on an HttpClient will send the following Accept header with a request if you do not override it:Accept: application/json, text/plain, */*
This suggests that it is OK if the server responds with text/plain (i.e., not JSON).
However, if the server responds with something similar to this (truncated), you will get an error.
Clearly text/plain is not a valid response type, and the default Accept header should be:
Accept: application/json
🔬 Minimal Reproduction
I will add this later if deemed necessary.
🔥 Exception or Error
🌍 Your Environment
Angular Version:
The text was updated successfully, but these errors were encountered: