check if the connection has been closed before doing the request to google servers
All checks were successful
CI / build (push) Successful in 54s
All checks were successful
CI / build (push) Successful in 54s
This commit is contained in:
parent
71abe2ae58
commit
a98a4ba1bf
1 changed files with 24 additions and 0 deletions
24
httppaths.go
24
httppaths.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -23,6 +24,17 @@ func forbiddenChecker(resp *http.Response, w http.ResponseWriter) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func connectionChecker(ctx context.Context) bool {
|
||||
// To check if the connection has been closed. To prevent
|
||||
// doing a useless request to google servers
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func videoplayback(w http.ResponseWriter, req *http.Request) {
|
||||
q := req.URL.Query()
|
||||
|
||||
|
@ -132,6 +144,10 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
|
|||
request.Header.Add("Origin", "https://www.youtube.com")
|
||||
request.Header.Add("Referer", "https://www.youtube.com/")
|
||||
|
||||
if connectionChecker(req.Context()) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
@ -222,6 +238,10 @@ func vi(w http.ResponseWriter, req *http.Request) {
|
|||
|
||||
request.Header.Set("User-Agent", default_ua)
|
||||
|
||||
if connectionChecker(req.Context()) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
@ -261,6 +281,10 @@ func ggpht(w http.ResponseWriter, req *http.Request) {
|
|||
log.Panic(err)
|
||||
}
|
||||
|
||||
if connectionChecker(req.Context()) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
|
Loading…
Reference in a new issue