From b65d715f0b200447b9cd5738cba549d51dca75d7 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 17 Oct 2021 16:51:35 +0200 Subject: [PATCH] hls: add Server header --- internal/core/api.go | 4 ++-- internal/core/hls_server.go | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/core/api.go b/internal/core/api.go index 2a91d9b6..8cd8f5e7 100644 --- a/internal/core/api.go +++ b/internal/core/api.go @@ -329,10 +329,10 @@ func (a *api) mwLog(ctx *gin.Context) { blw := &logWriter{ResponseWriter: ctx.Writer} ctx.Writer = blw - ctx.Next() - ctx.Writer.Header().Set("Server", "rtsp-simple-server") + ctx.Next() + var buf bytes.Buffer fmt.Fprintf(&buf, "%s %d %s\n", ctx.Request.Proto, ctx.Writer.Status(), http.StatusText(ctx.Writer.Status())) ctx.Writer.Header().Write(&buf) diff --git a/internal/core/hls_server.go b/internal/core/hls_server.go index d1c229f8..f0f7a8d7 100644 --- a/internal/core/hls_server.go +++ b/internal/core/hls_server.go @@ -142,15 +142,16 @@ func (s *hlsServer) onRequest(ctx *gin.Context) { // remove leading prefix pa := ctx.Request.URL.Path[1:] - ctx.Writer.Header().Add("Access-Control-Allow-Origin", s.hlsAllowOrigin) - ctx.Writer.Header().Add("Access-Control-Allow-Credentials", "true") + ctx.Writer.Header().Set("Server", "rtsp-simple-server") + ctx.Writer.Header().Set("Access-Control-Allow-Origin", s.hlsAllowOrigin) + ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true") switch ctx.Request.Method { case http.MethodGet: case http.MethodOptions: - ctx.Writer.Header().Add("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-Methods", "GET, OPTIONS") + ctx.Writer.Header().Set("Access-Control-Allow-Headers", ctx.Request.Header.Get("Access-Control-Request-Headers")) ctx.Writer.WriteHeader(http.StatusOK) return @@ -173,7 +174,7 @@ func (s *hlsServer) onRequest(ctx *gin.Context) { }() if fname == "" && !strings.HasSuffix(dir, "/") { - ctx.Writer.Header().Add("Location", "/"+dir+"/") + ctx.Writer.Header().Set("Location", "/"+dir+"/") ctx.Writer.WriteHeader(http.StatusMovedPermanently) return }