Former-commit-id: 9febac1ba701b29e59d7660540f03217f12cf9e0
This commit is contained in:
Gerasimos (Makis) Maropoulos 2019-08-06 15:45:30 +03:00
parent 3342ac5439
commit 8ac32ed27c

View File

@ -34,7 +34,7 @@ func (o *options) canOverride(method string) bool {
func (o *options) get(w http.ResponseWriter, r *http.Request) string { func (o *options) get(w http.ResponseWriter, r *http.Request) string {
for _, getter := range o.getters { for _, getter := range o.getters {
if v := getter(w, r); v != "" { if v := getter(w, r); v != "" {
return v return strings.ToUpper(v)
} }
} }
@ -198,7 +198,7 @@ func New(opt ...Option) router.WrapperFunc {
return func(w http.ResponseWriter, r *http.Request, proceed http.HandlerFunc) { return func(w http.ResponseWriter, r *http.Request, proceed http.HandlerFunc) {
originalMethod := strings.ToUpper(r.Method) originalMethod := strings.ToUpper(r.Method)
if opts.canOverride(originalMethod) { if opts.canOverride(originalMethod) {
newMethod := strings.ToUpper(opts.get(w, r)) newMethod := opts.get(w, r)
if newMethod != "" { if newMethod != "" {
if opts.saveOriginalMethodContextKey != nil { if opts.saveOriginalMethodContextKey != nil {
r = r.WithContext(stdContext.WithValue(r.Context(), opts.saveOriginalMethodContextKey, originalMethod)) r = r.WithContext(stdContext.WithValue(r.Context(), opts.saveOriginalMethodContextKey, originalMethod))