Skip to content

HttpClient tries and fails to parse the non-existent body of a HEAD request as JSON #19090

@karptonite

Description

@karptonite

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

this.http.head( anyUrl ) with throw an error because the body of the response is expected to be valid JSON, but no HEAD request should have a body. The workaround is to set responseType to "text", in the options.

Expected behavior

It seems that ideally HttpClient should know that a HEAD request has no body, and no try to parse it as JSON, or at least not throw an error when there is no body.

Minimal reproduction of the problem with instructions

use HttpClient to send any HEAD request.

What is the motivation / use case for changing the behavior?

I have a service which checks whether a resource exists without actually loading it, via a HEAD request.


Angular version: 5.0.0 Beta 6


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions