fix(gin): Do not panic when handling method not allowed on empty tree (#4003)

Signed-off-by: Pierre-Henri Symoneaux <pierre-henri.symoneaux@ovhcloud.com>
This commit is contained in:
Pierre-Henri Symoneaux
2024-06-22 16:19:04 +02:00
committed by GitHub
parent 9c081de9cd
commit 626d55b0c0
2 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -687,7 +687,7 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
break
}
if engine.HandleMethodNotAllowed {
if engine.HandleMethodNotAllowed && len(t) > 0 {
// According to RFC 7231 section 6.5.5, MUST generate an Allow header field in response
// containing a list of the target resource's currently supported methods.
allowed := make([]string, 0, len(t)-1)