[opt] 增加变量控制hls是否增加跨域头 #309

pull/312/head
q191201771 1 year ago
parent c492f7188b
commit c8602cf880

@ -16,6 +16,14 @@ var (
"Access-Control-Allow-Headers: Content-Type\r\n"
)
func AddCorsHeaders2HlsIfNeeded(w http.ResponseWriter) {
// TODO(chef): [opt] 为其他协议也增加配置项 202308
if AddCors2HlsFlag {
AddCorsHeaders(w)
}
}
func AddCorsHeaders(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Origin", "*")

@ -11,3 +11,6 @@ package base
import "github.com/q191201771/naza/pkg/nazalog"
var Log = nazalog.GetGlobalLogger()
// AddCors2HlsFlag 是否为hls增加跨域相关的http header
var AddCors2HlsFlag = true

@ -108,7 +108,7 @@ func (s *ServerHandler) ServeHTTPWithUrlCtx(resp http.ResponseWriter, req *http.
query.Set("session_id", session.sessionIdHash)
redirectUrl := urlObj.Path + "?" + query.Encode()
resp.Header().Add("Cache-Control", "no-cache")
base.AddCorsHeaders(resp)
base.AddCorsHeaders2HlsIfNeeded(resp)
http.Redirect(resp, req, redirectUrl, http.StatusFound)
return
}
@ -146,7 +146,7 @@ func (s *ServerHandler) ServeHTTPWithUrlCtx(resp http.ResponseWriter, req *http.
resp.Header().Add("Server", base.LalHlsTsServer)
}
resp.Header().Add("Cache-Control", "no-cache")
base.AddCorsHeaders(resp)
base.AddCorsHeaders2HlsIfNeeded(resp)
if sessionIdHash != "" {
session := s.getSubSession(sessionIdHash)

Loading…
Cancel
Save