mirror of https://github.com/portainer/portainer
fix(middlewares): fix data race in WithEndpoint() BE-11949 (#803)
parent
f07a3b1875
commit
036b87b649
|
@ -25,12 +25,12 @@ type key int
|
||||||
const contextEndpoint key = 0
|
const contextEndpoint key = 0
|
||||||
|
|
||||||
func WithEndpoint(endpointService dataservices.EndpointService, endpointIDParam string) mux.MiddlewareFunc {
|
func WithEndpoint(endpointService dataservices.EndpointService, endpointIDParam string) mux.MiddlewareFunc {
|
||||||
|
if endpointIDParam == "" {
|
||||||
|
endpointIDParam = "id"
|
||||||
|
}
|
||||||
|
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(rw http.ResponseWriter, request *http.Request) {
|
return http.HandlerFunc(func(rw http.ResponseWriter, request *http.Request) {
|
||||||
if endpointIDParam == "" {
|
|
||||||
endpointIDParam = "id"
|
|
||||||
}
|
|
||||||
|
|
||||||
endpointID, err := requesthelpers.RetrieveNumericRouteVariableValue(request, endpointIDParam)
|
endpointID, err := requesthelpers.RetrieveNumericRouteVariableValue(request, endpointIDParam)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httperror.WriteError(rw, http.StatusBadRequest, "Invalid environment identifier route variable", err)
|
httperror.WriteError(rw, http.StatusBadRequest, "Invalid environment identifier route variable", err)
|
||||||
|
@ -51,7 +51,6 @@ func WithEndpoint(endpointService dataservices.EndpointService, endpointIDParam
|
||||||
ctx := context.WithValue(request.Context(), contextEndpoint, endpoint)
|
ctx := context.WithValue(request.Context(), contextEndpoint, endpoint)
|
||||||
|
|
||||||
next.ServeHTTP(rw, request.WithContext(ctx))
|
next.ServeHTTP(rw, request.WithContext(ctx))
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue