Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome downloads the reloaded page on HTTP 205 response after an AJAX request

Working on a project, I just make an AJAX request to process some datas.
The server, once the job is done, returns a HTTP 205 RESET CONTENT response

I use this status code to tell the requester to reset the document view

Here is the piece of code I use

$.ajax({
    url: '/unread',
    method: 'PUT',
    data: {
        notifications: elements
    }
}).done(function(content, message, xhr) {
    if (205 !== xhr.status) {
        // Generic error message
        return;
    }

    window.location.reload(true)
}).fail(function() {
    // Generic error message
})

This works fine on Internet Explorer (8 and upwards), Firefox (28.0) and Opera (12.16). However Chrome (33.0) and Opera (20.0) instead of refreshing the page, downloads the response content of the page being reloadeddump when calling window.location.reload

Here's what I've tried

  • window.location.href = window.location.href gives the same result
  • history.go(0) gives the same result
  • If I remove the window.location.reload, nothing gets reloaded
  • Clearing the cache, removing the local state or going in private navigation doesn't change anything
  • If I change the response code (e.g 204), it works fine

Here is the visual network of what's happening

Chrome makes a download

Additionnal informations (and deeper investigations)

  • I'm on Ubuntu 12.04
  • Error could be reproduced on a different computer with Windows 7 (Same chrome version)
  • Error couldn't be reproduced on a different computer with Debian 7.1 (Same chrome version)

Why does Chrome and Opera behave like this on a 205 HTTP response?

like image 530
Touki Avatar asked Apr 07 '14 10:04

Touki


1 Answers

The closest I could find was that it might be a bug, because in this file: https://chromium.googlesource.com/chromium/chromium/+/trunk/net/http/http_stream_parser.cc

the comment starting at line 837 does not match the code at line 850: i.e. the comment doesn't mention that a 205 must be of zero length, but the code treats 205 like 1xx, 204, and 304. That was actually the only blink code I could find that mentioned 205 (outside of defining constants).

It might also be worth trying the latest Opera version; if the problem also happens there, it points the finger more strongly at a bug in the Blink source code.

like image 150
Darren Cook Avatar answered Sep 23 '22 12:09

Darren Cook