mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-07 07:21:22 +01:00
Remove the URL rewrite for docker registry request
This commit redirects the request to UI directory without URL rewrite
This commit is contained in:
parent
9f37a66f21
commit
7e6a13915b
@ -47,7 +47,7 @@ http {
|
||||
}
|
||||
|
||||
location /v2/ {
|
||||
proxy_pass http://ui/registryproxy/v2/;
|
||||
proxy_pass http://ui/v2/;
|
||||
proxy_set_header Host $$http_host;
|
||||
proxy_set_header X-Real-IP $$remote_addr;
|
||||
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
|
||||
|
@ -67,7 +67,7 @@ http {
|
||||
}
|
||||
|
||||
location /v2/ {
|
||||
proxy_pass http://ui/registryproxy/v2/;
|
||||
proxy_pass http://ui/v2/;
|
||||
proxy_set_header Host $$http_host;
|
||||
proxy_set_header X-Real-IP $$remote_addr;
|
||||
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
|
||||
|
@ -63,7 +63,7 @@ func init() {
|
||||
beego.Router("/reset", &CommonController{}, "post:ResetPassword")
|
||||
beego.Router("/userExists", &CommonController{}, "post:UserExists")
|
||||
beego.Router("/sendEmail", &CommonController{}, "get:SendResetEmail")
|
||||
beego.Router("/registryproxy/*", &RegistryProxy{}, "*:Handle")
|
||||
beego.Router("/v2/*", &RegistryProxy{}, "*:Handle")
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -175,17 +175,17 @@ func TestAll(t *testing.T) {
|
||||
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
||||
assert.Equal(int(400), w.Code, "'/sendEmail' httpStatusCode should be 400")
|
||||
|
||||
r, _ = http.NewRequest("GET", "/registryproxy/v2/", nil)
|
||||
r, _ = http.NewRequest("GET", "/v2/", nil)
|
||||
w = httptest.NewRecorder()
|
||||
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
||||
assert.Equal(int(200), w.Code, "ping v2 should get a 200 response")
|
||||
|
||||
r, _ = http.NewRequest("GET", "/registryproxy/v2/noproject/manifests/1.0", nil)
|
||||
r, _ = http.NewRequest("GET", "/v2/noproject/manifests/1.0", nil)
|
||||
w = httptest.NewRecorder()
|
||||
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
||||
assert.Equal(int(400), w.Code, "GET v2/noproject/manifests/1.0 should get a 400 response")
|
||||
|
||||
r, _ = http.NewRequest("GET", "/registryproxy/v2/project/notexist/manifests/1.0", nil)
|
||||
r, _ = http.NewRequest("GET", "/v2/project/notexist/manifests/1.0", nil)
|
||||
w = httptest.NewRecorder()
|
||||
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
||||
assert.Equal(int(404), w.Code, "GET v2/noproject/manifests/1.0 should get a 404 response")
|
||||
|
@ -118,7 +118,6 @@ type urlHandler struct {
|
||||
|
||||
func (uh urlHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
log.Debugf("in url handler, path: %s", req.URL.Path)
|
||||
req.URL.Path = strings.TrimPrefix(req.URL.Path, RegistryProxyPrefix)
|
||||
flag, repository, reference := MatchPullManifest(req)
|
||||
if flag {
|
||||
components := strings.SplitN(repository, "/", 2)
|
||||
@ -161,7 +160,7 @@ type readonlyHandler struct {
|
||||
func (rh readonlyHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
if config.ReadOnly() {
|
||||
if req.Method == http.MethodDelete || req.Method == http.MethodPost || req.Method == http.MethodPatch || req.Method == http.MethodPut {
|
||||
log.Warningf("The request is prohibited in readonly mode, url is: %s", req.URL.Path)
|
||||
log.Warningf("The request is prohibited in readonly mode, url is: %s", req.URL.Path)
|
||||
http.Error(rw, marshalError("DENIED", "The system is in read only mode. Any modification is prohibited."), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
@ -14,9 +14,6 @@ var Proxy *httputil.ReverseProxy
|
||||
|
||||
var handlers handlerChain
|
||||
|
||||
// RegistryProxyPrefix is the prefix of url on UI.
|
||||
const RegistryProxyPrefix = "/registryproxy"
|
||||
|
||||
type handlerChain struct {
|
||||
head http.Handler
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func initRouters() {
|
||||
beego.Router("/service/notifications/jobs/adminjob/:id([0-9]+)", &admin.Handler{}, "post:HandleAdminJob")
|
||||
beego.Router("/service/token", &token.Handler{})
|
||||
|
||||
beego.Router("/registryproxy/*", &controllers.RegistryProxy{}, "*:Handle")
|
||||
beego.Router("/v2/*", &controllers.RegistryProxy{}, "*:Handle")
|
||||
|
||||
//APIs for chart repository
|
||||
if config.WithChartMuseum() {
|
||||
|
Loading…
Reference in New Issue
Block a user