In Express 4, what's the best approach to forcing a particular MIME type to be used in a subsequent res.format(...) call?
Content negotiation works perfectly (when using curl and manual headers) but I'm in a browser where I want to force a PDF to be downloaded, so I need to override it on demand. I don't really want to have to make a whole new URL route for the same content (nasty and non-RESTy).
There are still references to req.accepted in the docs (under here: http://expressjs.com/api#req.accepts) but that doesn't seem to exist in the source code. Seems that the changes in Express 4 have changed the API somehow in a way that has slipped through the documentation.
I've tried res.type() and a whole bunch of other things that used to work, but to no avail.
I have an answer, but I don't much like it. I'm doing the following in my middleware:
knowledgeMiddleware = function(req, res, next) {
// Allow bypass on content negotiation when the mimeType
// query parameter is set
if (req.query.hasOwnProperty('mimeType')) {
req.headers.accept = req.query.mimeType;
delete req.query.mimeType;
}
...
next()
}
Any better ideas?