Firefox parsing empty payload

We make an XHR request with the following headers (I simplified it a bit):

POST http://localhost:9001/login Host: localhost:9001 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0 Accept: application/json, text/plain, */* Content-Type: application/json;charset=utf-8 Content-Length: 67 

Then our server responds like this (simplified again):

 Status code: 200 OK Cache-Control: no-cache, no-store Connection: close Content-Length: 0 Date: Mon, 27 Feb 2017 17:19:53 GMT Server: WildFly/9 Set-Cookie: JSESSIONID=123; path=/ 

There is no payload in the answer. Pay attention to Content-Length: 0 . But Firefox is still trying to parse it as XML. And it displays the following error on the console:

 XML Parsing Error: no root element found Location: http://localhost:9001/login Line Number 1, Column 1 

Please note: the server does not send a content-type header. And in accordance with RFC 7231, he needs to send a content-type header when there is real content.

So, is this a bug in Firefox, or is my research wrong?

Self reproduction

I wrote a small server and client to reproduce the problem.

server.js (start with node ./server.js ):

 const fs = require('fs'), http = require('http'); const server = http.createServer(function (request, response) { if (request.method === 'POST') { // send empty response response.end(); return; } // send file content fs.readFile('.' + request.url, function (error, content) { response.writeHead(200, { 'Content-Type': request.url === '/index.html' ? 'text/html' : 'text/javascript' }); response.end(content); }); }).listen(8080); 

index.html

 <script src="client.js"></script> 

client.js

 var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://localhost:8080/login'); xhr.send(); 

When opening the URL http: // localhost: 8080 / index.html in Firefox there will be an error in the JavaScript console.

Firefox version 51.0.1

+7
javascript firefox
source share

No one has answered this question yet.

See similar questions:

or similar:

5129
How to return a response from an asynchronous call?
3915
Why does Google add while (1); in your JSON answers?
2633
How to check for empty javascript object?
2597
How to check empty string / undefined / null in JavaScript?
2199
How to clear an array in JavaScript?
1635
JSON parsing in JavaScript?
410
Detect when browser downloads files
299
jQuery $ .ajax (), $ .post sends "OPTIONS" as REQUEST_METHOD in Firefox

All Articles