Firefox adds charset=UTF-8 when doing POST requests with ajax.

One of our customers reported some issues yesterday, all of a sudden they could not upload images in our custom built admin. They sent along a screenshot and I could see that our API responded with HTTP status code 415. Our API follows the JSON API standard and the specification says

Clients MUST send all JSON API data in request documents with the header Content-Type: application/vnd.api+json without any media type parameters.

So, if someone makes a request to our API with an incorrect Content-Type header, we return 415 with a nice error message.

I checked the logs and this is what I found:

{
	"errors": [{
		"status": "415",
		"title": "Unsupported Media Type",
		"detail": "You must use the 'application/vnd.api+json' Content-Type in your request. You had the following Content-Type: 'application/vnd.api+json; charset=UTF-8'"
	}]
}

Well, that's weird because I know that we explicitly set the Content-Type header to be application/vnd.api+json without any charset information.

Time to start digging.

After some googling I found the following bug report(it's over 10 years old!).
I did some more reading and it seems like Mozilla fixed the bug in version 44 of Firefox.

Version 44 came out in the beginning of year 2016...and I know that our customer is a big organization and they are always late on updating all of their stuff...so I asked our client and it turns out that they are running...Firefox 39. I rest my case.

So, the solution is to update Firefox to get rid of this annoying bug.

Firefox adds charset=UTF-8 when doing POST requests with ajax.
Share this