From c71830c1eed5febc2d1cdc89de18142fe91cb9e6 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 14 Jan 2024 20:34:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=AB=99=E8=AE=BE=E7=BD=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0HLS=E5=8A=A0=E5=AF=86=E5=8A=9F=E8=83=BD=EF=BC=88?= =?UTF-8?q?=E5=95=86=E4=B8=9A=E7=89=88=E6=9C=AC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request.go | 15 +++++++++++++++ internal/nodes/http_request_hls.go | 16 ++++++++++++++++ internal/nodes/http_request_reverse_proxy.go | 14 +++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 internal/nodes/http_request_hls.go diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index 35b0ba1..a737050 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -282,6 +282,16 @@ func (this *HTTPRequest) Do() { if this.web.Compression != nil && this.web.Compression.IsOn && this.web.Compression.Level > 0 { this.writer.SetCompression(this.web.Compression) } + + // HLS + if this.web.HLS != nil && + this.web.HLS.Encrypting != nil && + this.web.HLS.Encrypting.IsOn { + if this.processHLSBefore() { + this.doEnd() + return + } + } } // 开始调用 @@ -633,6 +643,11 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo this.web.CC = web.CC } + // HLS + if web.HLS != nil && (web.HLS.IsPrior || isTop) { + this.web.HLS = web.HLS + } + // 重写规则 if len(web.RewriteRefs) > 0 { for index, ref := range web.RewriteRefs { diff --git a/internal/nodes/http_request_hls.go b/internal/nodes/http_request_hls.go new file mode 100644 index 0000000..9ec4312 --- /dev/null +++ b/internal/nodes/http_request_hls.go @@ -0,0 +1,16 @@ +// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . +//go:build !plus + +package nodes + +import "net/http" + +func (this *HTTPRequest) processHLSBefore() (blocked bool) { + // stub + return false +} + +func (this *HTTPRequest) processM3u8Response(resp *http.Response) error { + // stub + return nil +} diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index 72ed02f..bef1f86 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -436,7 +436,19 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId if this.web.Optimization != nil && resp.Body != nil && this.cacheRef != nil /** must under cache **/ { err := this.web.Optimization.FilterResponse(this.URL(), resp) if err != nil { - this.write50x(err, http.StatusBadGateway, "Page Optimization: Fail to read content from origin", "内容优化:从源站读取内容失败", false) + this.write50x(err, http.StatusBadGateway, "Page Optimization: fail to read content from origin", "内容优化:从源站读取内容失败", false) + return + } + } + + // HLS + if this.web.HLS != nil && + this.web.HLS.Encrypting != nil && + this.web.HLS.Encrypting.IsOn && + resp.StatusCode == http.StatusOK { + m3u8Err := this.processM3u8Response(resp) + if m3u8Err != nil { + this.write50x(m3u8Err, http.StatusBadGateway, "m3u8 encrypt: fail to read content from origin", "m3u8加密:从源站读取内容失败", false) return } }