Skip to content

Commit 2fda79d

Browse files
committed
router: minor style fixes
1 parent b390476 commit 2fda79d

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

router.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -421,28 +421,25 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
421421

422422
if req.Method == http.MethodOptions && r.HandleOPTIONS {
423423
// Handle OPTIONS requests
424-
if allow := r.allowed(path, http.MethodOptions); len(allow) > 0 {
424+
if allow := r.allowed(path, http.MethodOptions); allow != "" {
425425
w.Header().Set("Allow", allow)
426426
if r.GlobalOPTIONS != nil {
427427
r.GlobalOPTIONS.ServeHTTP(w, req)
428428
}
429429
return
430430
}
431-
} else {
432-
// Handle 405
433-
if r.HandleMethodNotAllowed {
434-
if allow := r.allowed(path, req.Method); len(allow) > 0 {
435-
w.Header().Set("Allow", allow)
436-
if r.MethodNotAllowed != nil {
437-
r.MethodNotAllowed.ServeHTTP(w, req)
438-
} else {
439-
http.Error(w,
440-
http.StatusText(http.StatusMethodNotAllowed),
441-
http.StatusMethodNotAllowed,
442-
)
443-
}
444-
return
431+
} else if r.HandleMethodNotAllowed { // Handle 405
432+
if allow := r.allowed(path, req.Method); allow != "" {
433+
w.Header().Set("Allow", allow)
434+
if r.MethodNotAllowed != nil {
435+
r.MethodNotAllowed.ServeHTTP(w, req)
436+
} else {
437+
http.Error(w,
438+
http.StatusText(http.StatusMethodNotAllowed),
439+
http.StatusMethodNotAllowed,
440+
)
445441
}
442+
return
446443
}
447444
}
448445

0 commit comments

Comments
 (0)