Browse Source

Add Access-Control-Expose-Headers (#12446)

Fix #12424

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: silverwind <me@silverwind.io>
tags/v1.13.0-rc1
zeripath 3 years ago
parent
commit
2ef318e6f1
No account linked to committer's email address

+ 1
- 0
modules/context/context.go View File

@@ -222,6 +222,7 @@ func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interfa
ctx.Resp.Header().Set("Expires", "0")
ctx.Resp.Header().Set("Cache-Control", "must-revalidate")
ctx.Resp.Header().Set("Pragma", "public")
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
http.ServeContent(ctx.Resp, ctx.Req.Request, name, modtime, r)
}


+ 2
- 0
modules/lfs/server.go View File

@@ -183,6 +183,7 @@ func getContentHandler(ctx *context.Context) {
}

ctx.Resp.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", fromByte, toByte, meta.Size-fromByte))
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Range")
}
}

@@ -204,6 +205,7 @@ func getContentHandler(ctx *context.Context) {
decodedFilename, err := base64.RawURLEncoding.DecodeString(filename)
if err == nil {
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+string(decodedFilename)+"\"")
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
}
}


+ 1
- 0
routers/api/v1/admin/org.go View File

@@ -121,5 +121,6 @@ func GetAllOrgs(ctx *context.APIContext) {

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, &orgs)
}

+ 1
- 0
routers/api/v1/admin/user.go View File

@@ -370,5 +370,6 @@ func GetAllUsers(ctx *context.APIContext) {

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, &results)
}

+ 1
- 0
routers/api/v1/org/org.go View File

@@ -135,6 +135,7 @@ func GetAll(ctx *context.APIContext) {

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, &orgs)
}


+ 1
- 0
routers/api/v1/org/team.go View File

@@ -686,6 +686,7 @@ func SearchTeam(ctx *context.APIContext) {

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": true,
"data": apiTeams,

+ 1
- 0
routers/api/v1/repo/commits.go View File

@@ -211,6 +211,7 @@ func GetAllCommits(ctx *context.APIContext) {

ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, X-PerPage, X-Total, X-PageCount, X-HasMore, Link")

ctx.JSON(http.StatusOK, &apiCommits)
}

+ 3
- 0
routers/api/v1/repo/issue.go View File

@@ -173,6 +173,8 @@ func SearchIssues(ctx *context.APIContext) {
}

ctx.SetLinkHeader(issueCount, setting.UI.IssuePagingNum)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", issueCount))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
}

@@ -322,6 +324,7 @@ func ListIssues(ctx *context.APIContext) {

ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", ctx.Repo.Repository.NumIssues))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")

ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
}

+ 1
- 0
routers/api/v1/repo/pull.go View File

@@ -115,6 +115,7 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions)

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, &apiPrs)
}


+ 1
- 0
routers/api/v1/repo/repo.go View File

@@ -222,6 +222,7 @@ func Search(ctx *context.APIContext) {

ctx.SetLinkHeader(int(count), opts.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, api.SearchResults{
OK: true,
Data: results,

+ 1
- 0
routers/api/v1/repo/status.go View File

@@ -227,6 +227,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")

ctx.JSON(http.StatusOK, apiStatuses)
}

+ 2
- 0
routers/api/v1/user/repo.go View File

@@ -43,6 +43,7 @@ func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {

ctx.SetLinkHeader(int(count), opts.PageSize)
ctx.Header().Set("X-Total-Count", strconv.FormatInt(count, 10))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, &apiRepos)
}

@@ -129,6 +130,7 @@ func ListMyRepos(ctx *context.APIContext) {

ctx.SetLinkHeader(int(count), opts.ListOptions.PageSize)
ctx.Header().Set("X-Total-Count", strconv.FormatInt(count, 10))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
ctx.JSON(http.StatusOK, &results)
}


+ 1
- 0
routers/api/v1/user/user.go View File

@@ -82,6 +82,7 @@ func Search(ctx *context.APIContext) {

ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")

ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": true,

+ 2
- 0
routers/repo/download.go View File

@@ -42,8 +42,10 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+strings.ToLower(cs))
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name))
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
} else {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name))
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
}

_, err := ctx.Resp.Write(buf)

Loading…
Cancel
Save