diff options
Diffstat (limited to 'routes')
-rw-r--r-- | routes/repo/http.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/routes/repo/http.go b/routes/repo/http.go index b8f519ba..2724ee1c 100644 --- a/routes/repo/http.go +++ b/routes/repo/http.go @@ -56,6 +56,18 @@ func askCredentials(c *context.Context, status int, text string) { func HTTPContexter() macaron.Handler { return func(c *context.Context) { + if len(setting.HTTP.AccessControlAllowOrigin) > 0 { + // Set CORS headers for browser-based git clients + c.Resp.Header().Set("Access-Control-Allow-Origin", setting.HTTP.AccessControlAllowOrigin) + c.Resp.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") + + // Handle preflight OPTIONS request + if c.Req.Method == "OPTIONS" { + c.Status(http.StatusOK) + return + } + } + ownerName := c.Params(":username") repoName := strings.TrimSuffix(c.Params(":reponame"), ".git") repoName = strings.TrimSuffix(repoName, ".wiki") |