Change to get uri from http request, and response with relative path of resource.

This commit is contained in:
wy65701436 2016-04-24 21:10:15 -07:00
parent 94422e9a71
commit 9c655e710b
3 changed files with 8 additions and 15 deletions

View File

@ -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)
}

View File

@ -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 ...

View File

@ -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 ...