codegangsta/martini — pull request #166 by shirro (2014-02-09 08:48:12+00:00)
Title: Added Methods to Router interface for CORS&405

These issues I am trying to solve are as follows.

To provide a mechanism to provide a 405 Method Not Allowed which according to RFC2616 "MUST include an Allow header containing a list of valid methods for the requested resource". And to provide an OPTIONS response that satisfies CORS with Access-Control-Request-Method header.

As an existence proof of a use for this I have a CORS handler, https://github.com/shirro/martini-experiments/blob/master/cors.go , with a NotFound method which uses Methods to get a list of methods that are valid for the path and uses it to generate the Access-Control-Request-Method if it is an OPTIONS request or a 405 with Allow header if any methods were found.

Pros:
- Keeps things DRY as the NotFound handler can infer the methods from the URL path
- Only run from a NotFound handler so no impact on performance otherwise

Cons:
- Scanning all the routes to find methods is expensive
- Changes an interface