github.com/orderbynull/buffalo@v0.11.1/middleware/content_type.go (about) 1 package middleware 2 3 import "github.com/gobuffalo/buffalo" 4 5 // SetContentType on the request to desired type. This will 6 // override any content type sent by the client. 7 func SetContentType(s string) buffalo.MiddlewareFunc { 8 return func(next buffalo.Handler) buffalo.Handler { 9 return func(c buffalo.Context) error { 10 c.Request().Header.Set("Content-Type", s) 11 return next(c) 12 } 13 } 14 } 15 16 // AddContentType will add a secondary content type to 17 // a request. If no content type is sent by the client 18 // the default will be set, otherwise the client's 19 // content type will be used. 20 func AddContentType(s string) buffalo.MiddlewareFunc { 21 return func(next buffalo.Handler) buffalo.Handler { 22 return func(c buffalo.Context) error { 23 c.Request().Header.Add("Content-Type", s) 24 return next(c) 25 } 26 } 27 }