niclashoyer/http-accept — pull request #1 by benblank (2012-05-10 18:20:35+00:00)
Title: Add "best match" methods for each header

The attached commits add a read-only, non-enumerable `getBestMatch` property to each `req.accept.foo` array. This property is a method that will select the best available match between the parsed header and the candidates supplied to the function.

This method performs simple string matching with wildcard support for the `Accept-Charset`, `Accept-Encoding` and `Accept-Ranges` headers as well as the more complex matching and precedence specified for the `Accept` and `Accept-Language` headers specified in [RFC 2616 sections 14.1 and 14.1](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html), respectively.

Examples of usage have been added to README.md:

```coffeescript
encoding = (req.accept.encodings?.getBestMatch ["gzip", "deflate"]) ? "identity"
mediaType = req.accept.types?.getBestMatch ["text/html", "application/json" ,"application/xml"]
```

*NB — This is my first experience with CoffeeScript, so it's possible the code isn't fully idiomatic. However, I've tried to match CS idioms and existing code style as closely as possible.*