fix(api): allow PATCH in CORS so browsers can call the status endpoints (#1436)
The status endpoints (PATCH /v0/servers/{name}/status and the
per-version one) are served with PATCH, but the CORS middleware's
AllowedMethods lists GET/POST/PUT/DELETE/OPTIONS and never PATCH. So a
cross-origin browser preflight for those endpoints comes back without
the allow headers and the browser blocks the actual request. One-line
fix: add PATCH to the allowed methods.
While here, the existing CORS test turned out to be a placeholder that
never reaches the real wrapped handler (its own comments say so), which
is why this went unnoticed. Added a small Handler() accessor and a
proper preflight test that asserts each routed method including PATCH is
allowed.
This commit is contained in:
parent
c36b521bf1
commit
3a39b665ac
1 changed files with 69 additions and 0 deletions
|
|
@ -109,6 +109,7 @@ func NewServer(cfg *config.Config, registryService service.RegistryService, metr
|
|||
http.MethodGet,
|
||||
http.MethodPost,
|
||||
http.MethodPut,
|
||||
http.MethodPatch,
|
||||
http.MethodDelete,
|
||||
http.MethodOptions,
|
||||
},
|
||||
|
|
@ -147,6 +148,12 @@ func NewServer(cfg *config.Config, registryService service.RegistryService, metr
|
|||
return server
|
||||
}
|
||||
|
||||
// Handler returns the fully wrapped HTTP handler (middleware stack plus routes).
|
||||
// Exposed so tests can exercise the middleware, e.g. CORS, without binding a port.
|
||||
func (s *Server) Handler() http.Handler {
|
||||
return s.server.Handler
|
||||
}
|
||||
|
||||
// Start begins listening for incoming HTTP requests
|
||||
func (s *Server) Start() error {
|
||||
log.Printf("HTTP server starting on %s", s.config.ServerAddress)
|
||||
|
|
|
|||
Loading…
Reference in a new issue