Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

req.format should be respected if set elsewere #30

Merged
merged 1 commit into from Aug 8, 2011

Conversation

Projects
None yet
2 participants
Contributor

kmpm commented Aug 8, 2011

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.

Owner

tj commented Aug 8, 2011

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

@tj tj added a commit that referenced this pull request Aug 8, 2011

@tj tj Merge pull request #30 from kmpm/master
req.format should be respected if set elsewere
46887b8

@tj tj merged commit 46887b8 into expressjs:master Aug 8, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment