@@ -421,28 +421,25 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
421
421
422
422
if req .Method == http .MethodOptions && r .HandleOPTIONS {
423
423
// Handle OPTIONS requests
424
- if allow := r .allowed (path , http .MethodOptions ); len ( allow ) > 0 {
424
+ if allow := r .allowed (path , http .MethodOptions ); allow != "" {
425
425
w .Header ().Set ("Allow" , allow )
426
426
if r .GlobalOPTIONS != nil {
427
427
r .GlobalOPTIONS .ServeHTTP (w , req )
428
428
}
429
429
return
430
430
}
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
+ )
445
441
}
442
+ return
446
443
}
447
444
}
448
445
0 commit comments