gorilla/mux — pull request #34 by Crisfole (2013-08-29 16:38:06+00:00)
Title: Add `Route.Or`

Unfortunately the `Queries` and `Headers` method work on an all or nothing basis (either EVERYTHING matches, or it's not a match). This means that, especially for things like Content-Type headers, where you may want to allow flexible content-types, (for example: any one of the incorrect, but potentially used, json types listed in this question: http://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type) there's no natural way to express 'Any one of these content types'.

I added an `Or` method to *Route that allows expression alternatives easily. This could be useful for any of the scalar types as well (like Path or the like).

I'm not 100% pleased with how it turned out, as I dislike having to create an `AltRoute` method that creates a new route with the correct parent and other options, but doesn't get registered...it'd be nice if a Route could unregister iteself instead. Despite that, it certainly fixes the problem.

I think the best, but unfortunately breaking, way to fix this problem would be to make a `matchInMap` that is orthogonal to `matchInArray` and it simply checks if any of the key-val combinations match at all. You can already naturally express "and" in mux by adding a route matcher:

r.Headers("Content-Type", "application/json").Headers("X-Application-Name", "My-Application")

But you can't (easily) express an 'or' relationship except if the matchers themselves default to that behavior.