summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-01-15 05:05:27 +0800
committertechknowlogick <hello@techknowlogick.com>2019-01-14 16:05:27 -0500
commit270fa6d63b9a25021d9663bd6162f4933b7eb5ff (patch)
treeeccb0176116ee5c8daa88a5fe68720578cb675e9 /routers
parent5a081c7a800bbd94a4f8313f3b379c2691c05510 (diff)
downloadgitea-270fa6d63b9a25021d9663bd6162f4933b7eb5ff.tar.gz
gitea-270fa6d63b9a25021d9663bd6162f4933b7eb5ff.zip
Support CORS headers to git smart http protocol (#5719)
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/http.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go
index ec5fbe6c0d..1728a75fcb 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -27,6 +27,18 @@ import (
// HTTP implmentation git smart HTTP protocol
func HTTP(ctx *context.Context) {
+ if len(setting.Repository.AccessControlAllowOrigin) > 0 {
+ // Set CORS headers for browser-based git clients
+ ctx.Resp.Header().Set("Access-Control-Allow-Origin", setting.Repository.AccessControlAllowOrigin)
+ ctx.Resp.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, User-Agent")
+
+ // Handle preflight OPTIONS request
+ if ctx.Req.Method == "OPTIONS" {
+ ctx.Status(http.StatusOK)
+ return
+ }
+ }
+
username := ctx.Params(":username")
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")