增加代理方式拉取HDL功能

This commit is contained in:
langhuihui
2023-04-15 08:43:14 +08:00
parent f6f8a74953
commit a18e083e7e
2 changed files with 18 additions and 32 deletions

15
pull.go
View File

@@ -3,6 +3,7 @@ package hdl
import (
"io"
"net/http"
"net/url"
"os"
"strings"
@@ -31,7 +32,16 @@ func (puller *HDLPuller) Connect() (err error) {
HDLPlugin.Info("connect", zap.String("remoteURL", puller.RemoteURL))
if strings.HasPrefix(puller.RemoteURL, "http") {
var res *http.Response
if res, err = http.Get(puller.RemoteURL); err == nil {
client := http.DefaultClient
if puller.Puller.Config.Proxy != "" {
proxy, err := url.Parse(puller.Puller.Config.Proxy)
if err != nil {
return err
}
transport := &http.Transport{Proxy: http.ProxyURL(proxy)}
client = &http.Client{Transport: transport}
}
if res, err = client.Get(puller.RemoteURL); err == nil {
if res.StatusCode != http.StatusOK {
return io.EOF
}
@@ -87,6 +97,9 @@ func (puller *HDLPuller) Pull() (err error) {
puller.WriteAVCCAudio(puller.absTS, &frame, puller.pool)
case codec.FLV_TAG_TYPE_VIDEO:
puller.WriteAVCCVideo(puller.absTS, &frame, puller.pool)
case codec.FLV_TAG_TYPE_SCRIPT:
puller.Info("script", zap.ByteString("data", mem.Value))
frame.Recycle()
}
}
return