From 13269a7b8441615ecfa9c8149f49beb456c37ee3 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Wed, 13 Sep 2023 13:43:44 +0300 Subject: [PATCH] feat: better url validation: - Do not accept redirects. Usually on yt at least, redirect means the link is invalid. Hence, it redirects to the home page. - This is tested and it works well. trust. Signed-off-by: HeshamTB --- templates/download-result.html | 2 +- yt.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/download-result.html b/templates/download-result.html index 31e6e93..1316264 100644 --- a/templates/download-result.html +++ b/templates/download-result.html @@ -8,6 +8,6 @@ -Internal Error. Try Again later +Internal Error. Try Again later {{ end }} diff --git a/yt.go b/yt.go index 6bd6321..b48f430 100644 --- a/yt.go +++ b/yt.go @@ -31,7 +31,11 @@ func isValidURL(data string) bool { } - httpClient := &http.Client{} + httpClient := &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } resp, err := httpClient.Get(data) if err != nil {