Add Access-Control-Expose-Headers (#12446)
Fix #12424 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
Родитель
e266ba30cc
Коммит
2ef318e6f1
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче