Save image with correct file name extension

Firefox has a feature that I’d like to use in my add-on, but I don’t know how.

Description of the feature:
Suppose you want to download an image that has the wrong file extension, like this one:
http://www.furaffinity.net/view/18473875/
(safe for work)

The file extension is .png, but the image is actually a JPG.

When you right-click the image and select “Save Image As”, Firefox automatically adds .jpeg to the file name, so that it becomes:
1449785049.badsheep_taocowwinterbg.png.jpeg

Probably mime type detection. This comment says so - http://stackoverflow.com/questions/22659863/identify-xhr-ajax-response-while-listening-to-http-response-in-firefox-addon/22666208#comment34533730_22669514

You can get mimeType like this:

var httpChannel = aRequest.QueryInterface(Ci.nsIHttpChannel);
var mimeType = httpChannel.contentType;

Firefox has some fairly sophisticated image sniffing internally. It is not exposed to javascript, so I don’t think you can use it. Your best bet might be to write your own, or copy it. It is trivial to detect the three or four most common image formats.