hls: add Server header

This commit is contained in:
aler9
2021-10-17 16:51:35 +02:00
parent ef3fab477e
commit b65d715f0b
2 changed files with 8 additions and 7 deletions

View File

@@ -329,10 +329,10 @@ func (a *api) mwLog(ctx *gin.Context) {
blw := &logWriter{ResponseWriter: ctx.Writer} blw := &logWriter{ResponseWriter: ctx.Writer}
ctx.Writer = blw ctx.Writer = blw
ctx.Next()
ctx.Writer.Header().Set("Server", "rtsp-simple-server") ctx.Writer.Header().Set("Server", "rtsp-simple-server")
ctx.Next()
var buf bytes.Buffer var buf bytes.Buffer
fmt.Fprintf(&buf, "%s %d %s\n", ctx.Request.Proto, ctx.Writer.Status(), http.StatusText(ctx.Writer.Status())) fmt.Fprintf(&buf, "%s %d %s\n", ctx.Request.Proto, ctx.Writer.Status(), http.StatusText(ctx.Writer.Status()))
ctx.Writer.Header().Write(&buf) ctx.Writer.Header().Write(&buf)

View File

@@ -142,15 +142,16 @@ func (s *hlsServer) onRequest(ctx *gin.Context) {
// remove leading prefix // remove leading prefix
pa := ctx.Request.URL.Path[1:] pa := ctx.Request.URL.Path[1:]
ctx.Writer.Header().Add("Access-Control-Allow-Origin", s.hlsAllowOrigin) ctx.Writer.Header().Set("Server", "rtsp-simple-server")
ctx.Writer.Header().Add("Access-Control-Allow-Credentials", "true") ctx.Writer.Header().Set("Access-Control-Allow-Origin", s.hlsAllowOrigin)
ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
switch ctx.Request.Method { switch ctx.Request.Method {
case http.MethodGet: case http.MethodGet:
case http.MethodOptions: case http.MethodOptions:
ctx.Writer.Header().Add("Access-Control-Allow-Methods", "GET, OPTIONS") ctx.Writer.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
ctx.Writer.Header().Add("Access-Control-Allow-Headers", ctx.Request.Header.Get("Access-Control-Request-Headers")) ctx.Writer.Header().Set("Access-Control-Allow-Headers", ctx.Request.Header.Get("Access-Control-Request-Headers"))
ctx.Writer.WriteHeader(http.StatusOK) ctx.Writer.WriteHeader(http.StatusOK)
return return
@@ -173,7 +174,7 @@ func (s *hlsServer) onRequest(ctx *gin.Context) {
}() }()
if fname == "" && !strings.HasSuffix(dir, "/") { if fname == "" && !strings.HasSuffix(dir, "/") {
ctx.Writer.Header().Add("Location", "/"+dir+"/") ctx.Writer.Header().Set("Location", "/"+dir+"/")
ctx.Writer.WriteHeader(http.StatusMovedPermanently) ctx.Writer.WriteHeader(http.StatusMovedPermanently)
return return
} }