Comments (11)
This would be really useful. See here. It would be nice to do something like this:
r.HandleFunc("/myapp", MyHandler).
Methods("GET").
Headers("Accept", "application/vnd.myapp-v{version:[0-9]+}+json")
http.Handle("/", r)
Or:
r.HandleFunc("/myapp", MyHandler).
Methods("GET").
Headers("Accept", "application/vnd.myapp-v{version:[0-9]+}+{format:json|xml}")
http.Handle("/", r)
from mux.
+1
this:
r.HandleFunc("/path", MyHandler).
Methods("POST").
Headers("Content-Type", "application/json")
will not match a request with "Content-Type", "application/json;charset=UTF-8"
and this:
r.HandleFunc("/path", MyHandler).
Methods("POST").
Headers("Content-Type", "application/json;charset=UTF-8")
will not match a request with "Content-Type", "application/json"
from mux.
I've added regex support. An example of usage is as follows:
r := mux.NewRouter()
r.HandleFunc("/", RootHandler).Headers("Content-Type", "application/json.*")
http.ListenAndServe(":8080", r)
}
Now both requests will work:
curl -X GET -H "Content-Type: application/json" localhost:8080
curl -X GET -H "Content-Type: application/json;charset=UTF-8" localhost:8080
My personal uses were for handling application/(json|text)
from mux.
@eastwood isn't HeadersRegexp what should be used here?
from mux.
@bluehallu That's correct. Above comment is out of date. The documentation should be up to date with this, if anybody requires it
from mux.
@eastwood I've tested the code and it behaves as you'd expect, but the docs are in sync with your comment above:
"...Alternatively, you can provide a regular expression and match the header as follows..."
from mux.
Ah I see :) Good pickup, sorry about the confusion, must of been a legacy commit. I'll clean that up right away to fix the confusion. Alternatively, you can fix the change and make a pull request, the more contributors the merrier!
from mux.
#125 Should fix this up for us
from mux.
I wanted to make sure I wasn't misunderstanding this before doing a PR. All
fixed now so thanks :)
On Tue, 8 Sep 2015 12:34 Clinton Ryan [email protected] wrote:
#125 #125 Should fix this up for us
—
Reply to this email directly or view it on GitHub
#16 (comment).
from mux.
It would be nice to support capturing regex matches in mux.Vars()
(see my previous comment), similiar to how the router.HandlerFunc
does it.
from mux.
@jmassara please open a separate issue for that.
from mux.
Related Issues (20)
- [bug] Adding to GET the same endpoint with POST and different Queries ends up with inconsistent error messages
- [question] How to retrieve the handler func without the middleware? HOT 2
- [bug] HOT 17
- Path variable not parsed HOT 2
- [bug] : the link for gorilla mux logo is broken
- [feature] Add CONTRIBUTING.md HOT 4
- [bug]
- [question] Is it true? Is the GWT unarchived, for real? HOT 3
- CORS ERROR HOT 10
- JSON parsing failed HOT 7
- [BUG] Go can't find v2.0 HOT 1
- [BUG] MethodNotAllowedHandler does not work for subrouter with different routes HOT 9
- [BUG] Router does not distinguish between `/` and `%2F` in the request path HOT 1
- Cannot install gorilla/mux with new install command of go HOT 2
- [BUG] Index out of range in (*routeRegexp).Match HOT 1
- [FEATURE] Accidental omission of GetHeaders? HOT 1
- [BUG] API is probably broken for GetQueries per each method HOT 1
- [BUG] runtime error in (*routeRegexp).Match
- [FEATURE] Route metadata
- When I use the subrouter() method, Methods() only works on the last endpoint, and other than the last endpoint, the rest of the endpoints give a 404 instead of a 405 with the unrelated http method. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mux.