origin checker refactor (#7889)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
77a1dc1f2f
Коммит
1ccf093803
@@ -58,8 +58,8 @@ type CorsWrapper struct {
|
||||
}
|
||||
|
||||
func (cw *CorsWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if len(*cw.config().ServiceSettings.AllowCorsFrom) > 0 {
|
||||
if utils.OriginChecker(r) {
|
||||
if allowed := *cw.config().ServiceSettings.AllowCorsFrom; allowed != "" {
|
||||
if utils.CheckOrigin(r, allowed) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
||||
|
||||
if r.Method == "OPTIONS" {
|
||||
@@ -252,6 +252,13 @@ func (a *App) StopServer() {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) OriginChecker() func(*http.Request) bool {
|
||||
if allowed := *a.Config().ServiceSettings.AllowCorsFrom; allowed != "" {
|
||||
return utils.OriginChecker(allowed)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// This is required to re-use the underlying connection and not take up file descriptors
|
||||
func consumeAndClose(r *http.Response) {
|
||||
if r.Body != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user