Bug Tracker

Modify

Ticket #13922 (closed bug: fixed)

Opened 11 months ago

Last modified 11 months ago

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
Blocking: Blocked by:

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

});

Change History

comment:1 Changed 11 months 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 11 months 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 11 months ago by jaubourg (previous) (diff)

comment:3 Changed 11 months ago by jaubourg

  • Owner set to jaubourg
  • Priority changed from undecided to blocker
  • Status changed from new to assigned
  • Component changed from unfiled to ajax

comment:4 Changed 11 months ago by Julian Aubourg

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: a2cd89a795067d67d8212a4571991e5d2fb0ea8f

comment:5 Changed 11 months ago by dmethvin

  • Milestone changed from None to 1.10

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.