Skip to content

Commit 93bd893

Browse files
committed
Add Access-Control-Expose-Headers
Fix go-gitea#12424 Signed-off-by: Andrew Thornton <[email protected]>
1 parent e17e3f7 commit 93bd893

File tree

14 files changed

+19
-0
lines changed

14 files changed

+19
-0
lines changed

modules/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interfa
222222
ctx.Resp.Header().Set("Expires", "0")
223223
ctx.Resp.Header().Set("Cache-Control", "must-revalidate")
224224
ctx.Resp.Header().Set("Pragma", "public")
225+
ctx.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
225226
http.ServeContent(ctx.Resp, ctx.Req.Request, name, modtime, r)
226227
}
227228

modules/lfs/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func getContentHandler(ctx *context.Context) {
183183
}
184184

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

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

routers/api/v1/admin/org.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ func GetAllOrgs(ctx *context.APIContext) {
121121

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

routers/api/v1/admin/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,5 +370,6 @@ func GetAllUsers(ctx *context.APIContext) {
370370

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

routers/api/v1/org/org.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func GetAll(ctx *context.APIContext) {
135135

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

routers/api/v1/org/team.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ func SearchTeam(ctx *context.APIContext) {
686686

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

routers/api/v1/repo/commits.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ func GetAllCommits(ctx *context.APIContext) {
212212
ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
213213
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
214214

215+
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, X-PerPage, X-Total, X-PageCount, X-HasMore, Link")
215216
ctx.JSON(http.StatusOK, &apiCommits)
216217
}
217218

routers/api/v1/repo/issue.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ func SearchIssues(ctx *context.APIContext) {
173173
}
174174

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

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

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

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

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions)
115115

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

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ func Search(ctx *context.APIContext) {
222222

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

routers/api/v1/repo/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
227227

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

231232
ctx.JSON(http.StatusOK, apiStatuses)
232233
}

routers/api/v1/user/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
4343

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

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

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

routers/api/v1/user/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func Search(ctx *context.APIContext) {
8282

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

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

routers/repo/download.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
4242
ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+strings.ToLower(cs))
4343
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) {
4444
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name))
45+
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
4546
} else {
4647
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name))
48+
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
4749
}
4850

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

0 commit comments

Comments
 (0)