Skip to content

HTTP Accept header incorrect when requiring JSON response #48505

@Berbe

Description

@Berbe

Which @angular/* package(s) are the source of the bug?

common

Is this a regression?

No

Description

When requesting a JSON answer from HttpClient.get() with observe?: body and responseType?: json, which are the default values for those parameters, the Accept HTTP header is set to the application/json, text/plain, */* value, which accepts other responses than JSON, hence violation assumptions.

Currently, it would be necessary for a client application using angular/common to explicitely set an Accept HTTP header in the headers parameter of the HttpClient object to enforce what should already be driven by the responseType field.

When JSON is expected as the answer format, the HTTP client shall request this format only.
It would be nice that, by default, when no Accept HTTP header is set through the headers parameter of an HttpClient instance, the default value takes the responseType parameter into account.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

The problem exists in the current master branch at the time of this writing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: common/httpIssues related to HTTP and HTTP Client

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions