Bug Tracker

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13922 closed bug (fixed)

HEAD responses with application/json results parseerror

Reported by: julio.melo+jquery@… Owned by: jaubourg
Priority: blocker Milestone: 1.10
Component: ajax Version: 1.9.1
Keywords: Cc: jaubourg
Blocked by: Blocking:


Using ajax to fetch an URL using request type HEAD leads to parseerror when content-type is application/json on response. Using GET, it worked as expected.

According to RF2616, section 10.2.1 "HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body". When the type of request is HEAD, jQuery should accept empty response, even when content-type is defined as application/json.

This fails $.ajax({

url : "http://ip.jsontest.com/", type : "HEAD", success : function() { console.log("HEAD OK!"); }, error : function() { console.error("HEAD Failed!"); }


This is ok $.ajax({

url : "http://ip.jsontest.com/", type : "GET", success : function() { console.log("GET OK!"); }, error : function() { console.error("GET Failed!"); }


Change History (5)

comment:1 Changed 4 years ago by dmethvin

Cc: jaubourg added

It does seem like we shouldn't be parsing content on HEAD requests since no data is ever expected. This is a bit different than #13450 where the browser sets a content-type but has a content-length of 0 for a request that should return data.

comment:2 Changed 4 years ago by jaubourg

(Well, it's tempting to special case HEAD requests here but isn't the fact the server delivers a response to a HEAD request with an actual content-type the real issue here ? If there is not content, why is the server providing a content-type ?)

Scrap that, this IS a bug. The HEAD request is supposed to have the same headers as the GET request. It's getting late here ;)

Last edited 4 years ago by jaubourg (previous) (diff)

comment:3 Changed 4 years ago by jaubourg

Component: unfiledajax
Owner: set to jaubourg
Priority: undecidedblocker
Status: newassigned

comment:4 Changed 4 years ago by Julian Aubourg

Resolution: fixed
Status: assignedclosed

Handles HEAD requests as if they always were 204. Fixes #13922.

Changeset: a2cd89a795067d67d8212a4571991e5d2fb0ea8f

comment:5 Changed 4 years ago by dmethvin

Milestone: None1.10
Note: See TracTickets for help on using tickets.