-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle CORS requests #6289
Handle CORS requests #6289
Changes from all commits
e35c3a3
aa8b18b
1b7326a
0e20860
cdcc350
1e9267f
f98e157
4e355d7
941cbeb
77ed706
d21cafa
34811f7
ffd17b1
30c74e3
a1fd528
747d397
c2d32bb
9caf3ee
095e52c
beba88f
ab866c3
035c36f
a3633f2
7cd4f34
c995452
aee5375
b369256
4525788
e3d5742
0c56e5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCORSNotSet(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequestf(t, "GET", "/api/v1/version") | ||
session := loginUser(t, "user2") | ||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
assert.Equal(t, resp.Code, http.StatusOK) | ||
corsHeader := resp.Header().Get("Access-Control-Allow-Origin") | ||
assert.Equal(t, corsHeader, "", "Access-Control-Allow-Origin: generated header should match") // header not set | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package setting | ||
|
||
import ( | ||
"time" | ||
|
||
"code.gitea.io/gitea/modules/log" | ||
|
||
"github.com/go-macaron/cors" | ||
) | ||
|
||
var ( | ||
// CORSConfig defines CORS settings | ||
CORSConfig cors.Options | ||
// EnableCORS defines whether CORS settings is enabled or not | ||
EnableCORS bool | ||
lafriks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
func newCORSService() { | ||
sec := Cfg.Section("cors") | ||
// Check cors setting. | ||
EnableCORS = sec.Key("ENABLED").MustBool(false) | ||
|
||
maxAge := sec.Key("MAX_AGE").MustDuration(10 * time.Minute) | ||
|
||
CORSConfig = cors.Options{ | ||
Scheme: sec.Key("SCHEME").String(), | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
AllowDomain: sec.Key("ALLOW_DOMAIN").String(), | ||
AllowSubdomain: sec.Key("ALLOW_SUBDOMAIN").MustBool(), | ||
Methods: sec.Key("METHODS").Strings(","), | ||
MaxAgeSeconds: int(maxAge.Seconds()), | ||
AllowCredentials: sec.Key("ALLOW_CREDENTIALS").MustBool(), | ||
} | ||
|
||
if EnableCORS { | ||
log.Info("CORS Service Enabled") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am following the syntax from https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive