File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed
Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -320,6 +320,7 @@ with `net/http` can be used with chi's mux.
320320-----------------------------------------------------------------------------------------------------------
321321| chi/middlware Handler | description |
322322|:----------------------|:---------------------------------------------------------------------------------
323+ | AllowContentType | Explicit whitelist of accepted request Content-Types |
323324| Compress | Gzip compression for clients that accept compressed responses |
324325| GetHead | Automatically route undefined HEAD requests to GET handlers |
325326| Heartbeat | Monitoring endpoint to check the servers pulse |
@@ -330,6 +331,7 @@ with `net/http` can be used with chi's mux.
330331| Recoverer | Gracefully absorb panics and prints the stack trace |
331332| RequestID | Injects a request ID into the context of each request |
332333| RedirectSlashes | Redirect slashes on routing paths |
334+ | SetHeader | Short-hand middleware to set a response header key/value |
333335| StripSlashes | Strip slashes on routing paths |
334336| Throttle | Puts a ceiling on the number of concurrent requests |
335337| Timeout | Signals to the request context when the timeout deadline is reached |
Original file line number Diff line number Diff line change @@ -26,22 +26,19 @@ func AllowContentType(contentTypes ...string) func(next http.Handler) http.Handl
2626
2727 return func (next http.Handler ) http.Handler {
2828 fn := func (w http.ResponseWriter , r * http.Request ) {
29- s := strings .ToLower (strings .TrimSpace (strings .Split (r .Header .Get ("Content-Type" ), ";" )[0 ]))
29+ s := strings .ToLower (strings .TrimSpace (r .Header .Get ("Content-Type" )))
30+ if i := strings .Index (s , ";" ); i > - 1 {
31+ s = s [0 :i ]
32+ }
3033
31- f := false
3234 for _ , t := range cT {
3335 if t == s {
34- f = true
35- break
36+ next . ServeHTTP ( w , r )
37+ return
3638 }
3739 }
3840
39- if ! f {
40- w .WriteHeader (http .StatusUnsupportedMediaType )
41- return
42- }
43-
44- next .ServeHTTP (w , r )
41+ w .WriteHeader (http .StatusUnsupportedMediaType )
4542 }
4643 return http .HandlerFunc (fn )
4744 }
You can’t perform that action at this time.
0 commit comments