Add "Docker-Distribution-Api-Version" header for the 401 response of registry API

This is needed for "docker manifest" commands: https://github.com/docker/cli/issues/989

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2020-02-27 17:32:14 +08:00
parent 6709dfb13f
commit 40890d2635

View File

@ -130,6 +130,8 @@ func Middleware() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if err := checker.check(req); err != nil {
// the header is needed for "docker manifest" commands: https://github.com/docker/cli/issues/989
rw.Header().Set("Docker-Distribution-Api-Version", "registry/2.0")
serror.SendError(rw, ierror.UnauthorizedError(err).WithMessage(err.Error()))
return
}