Unverified Commit 4090aca9 authored by Devon Rifkin's avatar Devon Rifkin Committed by GitHub
Browse files

server: send 405 instead of 404 for unallowed methods (#10275)

Fixes: #5483
parent 92ce438d
......@@ -1170,6 +1170,7 @@ func (s *Server) GenerateRoutes(rc *ollama.Registry) (http.Handler, error) {
corsConfig.AllowOrigins = envconfig.AllowedOrigins()
r := gin.Default()
r.HandleMethodNotAllowed = true
r.Use(
cors.New(corsConfig),
allowedHostsMiddleware(s.addr),
......
......@@ -485,6 +485,16 @@ func TestRoutes(t *testing.T) {
}
},
},
{
Name: "Method Not Allowed",
Method: http.MethodGet,
Path: "/api/show",
Expected: func(t *testing.T, resp *http.Response) {
if resp.StatusCode != 405 {
t.Errorf("expected status code 405, got %d", resp.StatusCode)
}
},
},
}
modelsDir := t.TempDir()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment