Server: Django 1.4 running on Heroku. All requests are HTTPS.
My ajax calls look like this:
var data = {
username: form.find('input[name="username"]').val(),
email: form.find('input[name="email"]').val()
};
$.ajax({
url: '/register',
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'text',
headers: {
'X-CSRFToken': $.cookie('csrftoken')
}
});
Occasionally, parsing the request body on the server fails because request.body is completely empty. It's fairly rare, but since I use this idiom on many pages, I see it a few times each week. Probably about 2-5% of these requests.
The CSRF token header is there along with the rest, so it appears that only the body itself is missing. In a recent request, I noticed a CONTENT_LENGTH 2 header as well, which would be too short to contain the real request data. I wonder where that got added.
I would love some help debugging this. I can't see any way for the JSON.stringify call to return the empty string. Is that reasonable? If so, then it has to be that the request body is either getting stripped off in-flight, or something in my Django application is doing it.
Any help debugging or ideas on how to reproduce this would be most welcome.