mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-25 19:56:09 +01:00
Merge pull request #10967 from ywk253100/200307_auth_header
Only set "Www-Authenticate" header for registry API
This commit is contained in:
commit
52c6d354d1
@ -59,9 +59,6 @@ func SendError(w http.ResponseWriter, err error) {
|
||||
// only log the error whose status code < 500 when debugging to avoid log flooding
|
||||
log.Debug(errPayload)
|
||||
}
|
||||
if statusCode == http.StatusUnauthorized {
|
||||
w.Header().Set("Www-Authenticate", `Basic realm="harbor"`)
|
||||
}
|
||||
w.WriteHeader(statusCode)
|
||||
fmt.Fprintln(w, errPayload)
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ func TestSendError(t *testing.T) {
|
||||
SendError(rw, err)
|
||||
assert.Equal(t, http.StatusUnauthorized, rw.Code)
|
||||
assert.Equal(t, `{"errors":[{"code":"UNAUTHORIZED","message":"unauthorized"}]}`+"\n", rw.Body.String())
|
||||
assert.Equal(t, `Basic realm="harbor"`, rw.Header().Get("Www-Authenticate"))
|
||||
|
||||
// internal server error
|
||||
rw = httptest.NewRecorder()
|
||||
|
@ -132,6 +132,7 @@ func Middleware() func(http.Handler) http.Handler {
|
||||
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")
|
||||
rw.Header().Set("Www-Authenticate", `Basic realm="harbor"`)
|
||||
serror.SendError(rw, ierror.UnauthorizedError(err).WithMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user