Restrict to YouTube related domains
This commit is contained in:
parent
6019c4efd1
commit
016a677be7
1 changed files with 30 additions and 0 deletions
30
main.go
30
main.go
|
@ -42,6 +42,13 @@ var h2client = &http.Client{
|
||||||
// user agent to use
|
// user agent to use
|
||||||
var ua = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101"
|
var ua = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101"
|
||||||
|
|
||||||
|
var allowed_hosts = []string{
|
||||||
|
"youtube.com",
|
||||||
|
"googlevideo.com",
|
||||||
|
"ytimg.com",
|
||||||
|
"ggpht.com",
|
||||||
|
}
|
||||||
|
|
||||||
type requesthandler struct{}
|
type requesthandler struct{}
|
||||||
|
|
||||||
func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -63,6 +70,29 @@ func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(strings.ToLower(host), ".")
|
||||||
|
|
||||||
|
if len(parts) < 2 {
|
||||||
|
io.WriteString(w, "Invalid hostname.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
domain := parts[len(parts)-2] + "." + parts[len(parts)-1]
|
||||||
|
|
||||||
|
disallowed := true
|
||||||
|
|
||||||
|
for _, value := range allowed_hosts {
|
||||||
|
if domain == value {
|
||||||
|
disallowed = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if disallowed {
|
||||||
|
io.WriteString(w, "Non YouTube domains are not supported.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
path := req.URL.EscapedPath()
|
path := req.URL.EscapedPath()
|
||||||
|
|
||||||
path = strings.Replace(path, "/ggpht", "", 1)
|
path = strings.Replace(path, "/ggpht", "", 1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue