Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accepted type negotiation #47

Open
bergie opened this issue Jan 3, 2012 · 3 comments
Open

Add accepted type negotiation #47

bergie opened this issue Jan 3, 2012 · 3 comments

Comments

@bergie
Copy link

bergie commented Jan 3, 2012

Currently express-resource uses the :format parameters for matching requested resource format (.xml, .json, etc).

In addition to this, it would be nice to support the HTTP Accept headers. connect-conneg provides a parser for them that organizes the requested formats by preference.

This can already be used with express-resource, but requires some boilerplate. First you need to add the conneg middleware:

server.use require('connect-conneg').acceptedTypes

And then handle the types in the default content negotiation handler:

default: (req, res, next) ->
  for type in req.acceptableTypes
    if this.html and type is 'text/html'
      return this.html req, res, next
    if this.json and type is 'application/json'
      return this.json req, res, next
  next()

It would be very useful if the default implementation of default did this, instead of falling back to 406 error.

@tj
Copy link
Member

tj commented Jan 3, 2012

express 3x will have all these https://github.com/visionmedia/express/blob/master/lib/request.js#L153
but yup I agree this would be nice to have

@bergie
Copy link
Author

bergie commented Jan 4, 2012

@visionmedia great! It would be good to support the new Express 3x feature (req.accepted) and connect-conneg (req.acceptableTypes).

Want a pull request?

@tj
Copy link
Member

tj commented Jan 4, 2012

yeah we could use that for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants