feat: change how headers are passed to the client and move constant variables
This commit is contained in:
parent
f7e75ce5e7
commit
e8d7b14d82
4 changed files with 46 additions and 40 deletions
|
@ -20,21 +20,6 @@ var allowed_hosts = []string{
|
|||
"googleusercontent.com",
|
||||
}
|
||||
|
||||
var strip_headers = []string{
|
||||
"Accept-Encoding",
|
||||
"Authorization",
|
||||
"Origin",
|
||||
"Referer",
|
||||
"Cookie",
|
||||
"Set-Cookie",
|
||||
"Etag",
|
||||
"Alt-Svc",
|
||||
"Server",
|
||||
"Cache-Control",
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-to
|
||||
"report-to",
|
||||
}
|
||||
|
||||
var videoplayback_headers = http.Header{
|
||||
"Accept": {"*/*"},
|
||||
"Accept-Encoding": {"gzip, deflate, br, zstd"},
|
||||
|
@ -42,3 +27,6 @@ var videoplayback_headers = http.Header{
|
|||
"Origin": {"https://www.youtube.com"},
|
||||
"Referer": {"https://www.youtube.com/"},
|
||||
}
|
||||
|
||||
// https://github.com/FreeTubeApp/FreeTube/blob/5a4cd981cdf2c2a20ab68b001746658fd0c6484e/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js#L1097
|
||||
var protobuf_body = []byte{0x78, 0} // protobuf body
|
||||
|
|
|
@ -123,10 +123,7 @@ func Videoplayback(w http.ResponseWriter, req *http.Request) {
|
|||
|
||||
proxyURL.RawQuery = q.Encode()
|
||||
|
||||
// https://github.com/FreeTubeApp/FreeTube/blob/5a4cd981cdf2c2a20ab68b001746658fd0c6484e/src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js#L1097
|
||||
body := []byte{0x78, 0} // protobuf body
|
||||
|
||||
postRequest, err := http.NewRequest("POST", proxyURL.String(), bytes.NewReader(body))
|
||||
postRequest, err := http.NewRequest("POST", proxyURL.String(), bytes.NewReader(protobuf_body))
|
||||
if err != nil {
|
||||
log.Panic("Failed to create postRequest:", err)
|
||||
}
|
||||
|
@ -184,8 +181,7 @@ func Videoplayback(w http.ResponseWriter, req *http.Request) {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
NoRewrite := strings.HasPrefix(resp.Header.Get("Content-Type"), "audio") || strings.HasPrefix(resp.Header.Get("Content-Type"), "video")
|
||||
utils.CopyHeaders(resp.Header, w.Header(), NoRewrite)
|
||||
utils.CopyHeadersNew(resp.Header, w.Header())
|
||||
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
|
||||
|
|
28
internal/utils/consts.go
Normal file
28
internal/utils/consts.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package utils
|
||||
|
||||
const (
|
||||
path_prefix = ""
|
||||
)
|
||||
|
||||
var strip_headers = []string{
|
||||
"Accept-Encoding",
|
||||
"Authorization",
|
||||
"Origin",
|
||||
"Referer",
|
||||
"Cookie",
|
||||
"Set-Cookie",
|
||||
"Etag",
|
||||
"Alt-Svc",
|
||||
"Server",
|
||||
"Cache-Control",
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-to
|
||||
"report-to",
|
||||
}
|
||||
|
||||
var headers_for_response = []string{
|
||||
"Content-Length",
|
||||
"Accept-Ranges",
|
||||
"Content-Type",
|
||||
"Expires",
|
||||
"Last-Modified",
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -9,25 +12,6 @@ import (
|
|||
"git.nadeko.net/Fijxu/http3-ytproxy/internal/httpc"
|
||||
)
|
||||
|
||||
const (
|
||||
path_prefix = ""
|
||||
)
|
||||
|
||||
var strip_headers = []string{
|
||||
"Accept-Encoding",
|
||||
"Authorization",
|
||||
"Origin",
|
||||
"Referer",
|
||||
"Cookie",
|
||||
"Set-Cookie",
|
||||
"Etag",
|
||||
"Alt-Svc",
|
||||
"Server",
|
||||
"Cache-Control",
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-to
|
||||
"report-to",
|
||||
}
|
||||
|
||||
func CopyHeaders(from http.Header, to http.Header, length bool) {
|
||||
// Loop over header names
|
||||
outer:
|
||||
|
@ -49,6 +33,16 @@ outer:
|
|||
}
|
||||
}
|
||||
|
||||
func CopyHeadersNew(from http.Header, to http.Header) {
|
||||
for from_header, value := range from {
|
||||
for _, header := range headers_for_response {
|
||||
if from_header == header {
|
||||
to.Add(header, value[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetBestThumbnail(path string) (newpath string) {
|
||||
|
||||
formats := [4]string{"maxresdefault.jpg", "sddefault.jpg", "hqdefault.jpg", "mqdefault.jpg"}
|
||||
|
|
Loading…
Add table
Reference in a new issue