Permalink
Browse files

Set content on the XmlHttpRequest object when sending a DELETE request.

Nginx will consistently reply with a 411 - Content-Length Required error when sending a DELETE request with no Content-Length.  Chrome does not send a content-length with a DELETE request unless there is content in the request.  Doesn't look like they're gonna fix it (see https://groups.google.com/a/chromium.org/d/msg/chromium-bugs/tkF4sDBPYrs/DFN1cMs5bo4J).
  • Loading branch information...
1 parent 6a60dac commit ee4c5f431b6b276b44c81d0ca219a281fd6a841d @mjumbewu mjumbewu committed Aug 27, 2012
Showing with 7 additions and 0 deletions.
  1. +7 −0 src/sa_web/static/sa/js/models.js
@@ -123,6 +123,13 @@ jQuery(document).ajaxSend(function(event, xhr, settings) {
if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
+
+ // If this is a DELETE request, explicitly set the data to be sent so that
+ // the browser will calculate a value for the Content-Length header.
+ if (settings.type === 'DELETE') {
+ xhr.setRequestHeader("Content-Type", "application/json");
+ settings.data = '{}';
+ }
});
// Disable caching for all ajax calls. This is required because IE

0 comments on commit ee4c5f4

Please sign in to comment.