mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
fix(search): added the missing headers for search route (#1438)
- added allow methods and allowed headers Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
parent
ea79be64da
commit
b7ef88c96d
2 changed files with 32 additions and 7 deletions
|
@ -179,11 +179,27 @@ func SetupSearchRoutes(config *config.Config, router *mux.Router, storeControlle
|
||||||
resConfig := search.GetResolverConfig(log, storeController, repoDB, cveInfo)
|
resConfig := search.GetResolverConfig(log, storeController, repoDB, cveInfo)
|
||||||
|
|
||||||
extRouter := router.PathPrefix(constants.ExtSearchPrefix).Subrouter()
|
extRouter := router.PathPrefix(constants.ExtSearchPrefix).Subrouter()
|
||||||
|
extRouter.Use(SearchACHeadersHandler())
|
||||||
extRouter.Methods("GET", "POST", "OPTIONS").
|
extRouter.Methods("GET", "POST", "OPTIONS").
|
||||||
Handler(addSearchSecurityHeaders(gqlHandler.NewDefaultServer(gql_generated.NewExecutableSchema(resConfig))))
|
Handler(addSearchSecurityHeaders(gqlHandler.NewDefaultServer(gql_generated.NewExecutableSchema(resConfig))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SearchACHeadersHandler() mux.MiddlewareFunc {
|
||||||
|
return func(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
resp.Header().Set("Access-Control-Allow-Methods", "HEAD,GET,POST,OPTIONS")
|
||||||
|
resp.Header().Set("Access-Control-Allow-Headers", "Authorization,content-type")
|
||||||
|
|
||||||
|
if req.Method == http.MethodOptions {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next.ServeHTTP(resp, req)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getExtension(name, url, description string, endpoints []string) distext.Extension {
|
func getExtension(name, url, description string, endpoints []string) distext.Extension {
|
||||||
return distext.Extension{
|
return distext.Extension{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
|
|
@ -31,20 +31,29 @@ func SetupUserPreferencesRoutes(config *config.Config, router *mux.Router, store
|
||||||
log.Info().Msg("setting up user preferences routes")
|
log.Info().Msg("setting up user preferences routes")
|
||||||
|
|
||||||
userprefsRouter := router.PathPrefix(constants.ExtUserPreferencesPrefix).Subrouter()
|
userprefsRouter := router.PathPrefix(constants.ExtUserPreferencesPrefix).Subrouter()
|
||||||
|
userprefsRouter.Use(UserPrefsACHeadersHandler())
|
||||||
|
|
||||||
userprefsRouter.HandleFunc("", HandleUserPrefs(repoDB, log)).Methods(zcommon.AllowedMethods(http.MethodPut)...)
|
userprefsRouter.HandleFunc("", HandleUserPrefs(repoDB, log)).Methods(zcommon.AllowedMethods(http.MethodPut)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UserPrefsACHeadersHandler() mux.MiddlewareFunc {
|
||||||
|
return func(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
resp.Header().Set("Access-Control-Allow-Methods", "HEAD,GET,POST,PUT,OPTIONS")
|
||||||
|
resp.Header().Set("Access-Control-Allow-Headers", "Authorization,content-type")
|
||||||
|
|
||||||
|
if req.Method == http.MethodOptions {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next.ServeHTTP(resp, req)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func HandleUserPrefs(repoDB repodb.RepoDB, log log.Logger) func(w http.ResponseWriter, r *http.Request) {
|
func HandleUserPrefs(repoDB repodb.RepoDB, log log.Logger) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(rsp http.ResponseWriter, req *http.Request) {
|
return func(rsp http.ResponseWriter, req *http.Request) {
|
||||||
rsp.Header().Set("Access-Control-Allow-Methods", "HEAD,GET,POST,PUT,OPTIONS")
|
|
||||||
rsp.Header().Set("Access-Control-Allow-Headers", "Authorization,content-type")
|
|
||||||
|
|
||||||
if req.Method == http.MethodOptions {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !queryHasParams(req.URL.Query(), []string{"action"}) {
|
if !queryHasParams(req.URL.Query(), []string{"action"}) {
|
||||||
rsp.WriteHeader(http.StatusBadRequest)
|
rsp.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue