Skip to content

Commit

Permalink
fix: status code 200 maybe a range resp
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Nov 2, 2024
1 parent 31fcf5e commit 6f49476
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 0 additions & 7 deletions server/handlers/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,9 @@ func ProxyURL(ctx *gin.Context, u string, headers map[string]string, opts ...Pro
cli := http.Client{
Transport: uhc.DefaultTransport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
req.Header.Del("Referer")
for k, v := range headers {
req.Header.Set(k, v)
}
if r := ctx.GetHeader("Range"); r != "" {
req.Header.Set("Range", r)
}
if r := ctx.GetHeader("Accept-Encoding"); r != "" {
req.Header.Set("Accept-Encoding", r)
}
if req.Header.Get("User-Agent") == "" {
req.Header.Set("User-Agent", utils.UA)
}
Expand Down
24 changes: 19 additions & 5 deletions server/handlers/proxy/readseeker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/synctv-org/synctv/utils"
"github.com/zijiren233/go-uhc"
)

var (
Expand Down Expand Up @@ -131,7 +132,6 @@ func NewHttpReadSeekCloser(url string, conf ...HttpReadSeekerConf) *HttpReadSeek
headMethod: http.MethodHead,
perLength: 1024 * 1024 * 16,
headers: make(http.Header),
client: http.DefaultClient,
}

for _, c := range conf {
Expand All @@ -155,15 +155,26 @@ func (h *HttpReadSeekCloser) fix() *HttpReadSeekCloser {
if h.ctx == nil {
h.ctx = context.Background()
}
if h.client == nil {
h.client = http.DefaultClient
}
if h.perLength <= 0 {
h.perLength = 1024 * 1024
}
if h.headers == nil {
h.headers = make(http.Header)
}
if h.client == nil {
h.client = &http.Client{
Transport: uhc.DefaultTransport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
for k, v := range h.headers {
req.Header[k] = v
}
if req.Header.Get("User-Agent") == "" {
req.Header.Set("User-Agent", utils.UA)
}
return nil
},
}
}
return h
}

Expand Down Expand Up @@ -242,7 +253,10 @@ func (h *HttpReadSeekCloser) FetchNextChunk() error {

h.contentType = resp.Header.Get("Content-Type")

if resp.StatusCode == http.StatusOK {
if resp.StatusCode == http.StatusOK &&
resp.Header.Get("Accept-Ranges") != "bytes" &&
resp.Header.Get("Content-Range") == "" {

if h.offset > 0 {
if h.notSupportSeekWhenNotSupportRange {
return fmt.Errorf("not support seek when not support range")
Expand Down

0 comments on commit 6f49476

Please sign in to comment.