diff --git a/api/base.go b/api/base.go index c44b7bec23..f2529b61e2 100644 --- a/api/base.go +++ b/api/base.go @@ -87,8 +87,10 @@ func (b *BaseAPI) ValidateUser() int { return userID } -// Redirect does redirection to localurl with http header status code. -// It sends http response header directly. -func (b *BaseAPI) Redirect(statusCode int, location string) { - b.Ctx.Redirect(statusCode, location) +// Redirect does redirection to resource URI with http header status code. +func (b *BaseAPI) Redirect(statusCode int, resouceID string) { + requestURI := b.Ctx.Request.RequestURI + resoucreURI := requestURI + "/" + resouceID + + b.Ctx.Redirect(statusCode, resoucreURI) } diff --git a/api/project.go b/api/project.go index d71c6d02b9..7e6f46e7ec 100644 --- a/api/project.go +++ b/api/project.go @@ -18,8 +18,6 @@ package api import ( "fmt" "net/http" - "os" - "strings" "github.com/vmware/harbor/dao" "github.com/vmware/harbor/models" @@ -34,7 +32,6 @@ type ProjectAPI struct { BaseAPI userID int projectID int64 - HarborURL string } type projectReq struct { @@ -46,8 +43,6 @@ const projectNameMaxLen int = 30 // Prepare validates the URL and the user func (p *ProjectAPI) Prepare() { - p.HarborURL = strings.ToLower(os.Getenv("HARBOR_URL")) - p.userID = p.ValidateUser() idStr := p.Ctx.Input.Param(":id") if len(idStr) > 0 { @@ -98,8 +93,7 @@ func (p *ProjectAPI) Post() { p.RenderError(http.StatusInternalServerError, "Failed to add project") } - projectLocation := p.HarborURL + "/api/projects/" + strconv.FormatInt(projectID, 10) - p.Redirect(http.StatusCreated, projectLocation) + p.Redirect(http.StatusCreated, strconv.FormatInt(projectID, 10)) } // Head ... diff --git a/api/user.go b/api/user.go index e9d8aaae04..c9bb998001 100644 --- a/api/user.go +++ b/api/user.go @@ -34,7 +34,6 @@ type UserAPI struct { SelfRegistration bool IsAdmin bool AuthMode string - HarborURL string } type passwordReq struct { @@ -55,7 +54,6 @@ func (ua *UserAPI) Prepare() { if selfRegistration == "on" { ua.SelfRegistration = true } - ua.HarborURL = strings.ToLower(os.Getenv("HARBOR_URL")) if ua.Ctx.Input.IsPost() { sessionUserID := ua.GetSession("userId") @@ -167,8 +165,7 @@ func (ua *UserAPI) Post() { return } - userLocation := ua.HarborURL + "/api/users/" + strconv.FormatInt(userID, 10) - ua.Redirect(http.StatusCreated, userLocation) + ua.Redirect(http.StatusCreated, strconv.FormatInt(userID, 10)) } // Delete ...