visionmedia / express-resource

Resourceful routing for Express
1.41k stars 140 forks source link

req.format should be respected if set elsewere #30

Closed kmpm closed 13 years ago

kmpm commented 13 years ago

I have made a small middleware that sets the req.format depending on the accept header.

app.all('/myresource/*', function(req, res, next){
    if(req.headers.accept){
        if(req.headers.accept == 'application/json') req.format='json';
    }
    next();
});

But I found out that req.format was overwritten in the map function. This change keeps the req.format unless req.params.format format is set which i think should overrule them.

This gives that you can use whatever you set in middleware as a suggestion for format unless it's specifically given on the url.

tj commented 13 years ago

cool, I like it, when the Accept content-negotiation is in this will be nice to automate like you're doing right now. In some sense I would like to replace these .format things with Accept, they are kinda hacky and can lead to some stupid bugs