handle user-agent header based on  query param
All checks were successful
CI / build (push) Successful in 3m39s

This commit is contained in:
Fijxu 2024-12-16 02:34:09 -03:00
parent 46d11bfa53
commit 03a37009c4
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

View file

@ -38,6 +38,7 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
}
host := q.Get("host")
c := q.Get("c")
q.Del("host")
if len(host) <= 0 {
@ -95,11 +96,21 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
body := []byte{0x78, 0} // protobuf body
request, err := http.NewRequest("POST", proxyURL.String(), bytes.NewReader(body))
copyHeaders(req.Header, request.Header, false)
request.Header.Set("User-Agent", ua)
if err != nil {
log.Panic(err)
}
copyHeaders(req.Header, request.Header, false)
switch c {
case "ANDROID":
request.Header.Set("User-Agent", "com.google.android.youtube/1537338816 (Linux; U; Android 13; en_US; ; Build/TQ2A.230505.002; Cronet/113.0.5672.24)")
case "IOS":
request.Header.Set("User-Agent", "com.google.ios.youtube/19.32.8 (iPhone14,5; U; CPU iOS 17_6 like Mac OS X;)")
case "WEB":
request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
default:
request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
}
resp, err := client.Do(request)
if err != nil {