Skip to main content

Bug Tracker

Side navigation

#13922 closed bug (fixed)

Opened May 22, 2013 08:02PM UTC

Closed May 23, 2013 12:35AM UTC

Last modified May 24, 2013 03:27AM UTC

HEAD responses with application/json results parseerror

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

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!"); }

});

Attachments (0)
Change History (5)

Changed May 22, 2013 08:49PM UTC by dmethvin comment:1

cc: → jaubourg

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.

Changed May 22, 2013 11:22PM UTC by jaubourg comment:2

_comment0: 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 ?1369265108327835

(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 ;)

Changed May 22, 2013 11:25PM UTC by jaubourg comment:3

component: unfiledajax
owner: → jaubourg
priority: undecidedblocker
status: newassigned

Changed May 23, 2013 12:35AM UTC by Julian Aubourg comment:4

resolution: → fixed
status: assignedclosed

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

Changeset: a2cd89a795067d67d8212a4571991e5d2fb0ea8f

Changed May 24, 2013 03:27AM UTC by dmethvin comment:5

milestone: None1.10