diff --git a/internal/pkg/crawl/sitespecific/reddit/reddit.go b/internal/pkg/crawl/sitespecific/reddit/reddit.go new file mode 100644 index 00000000..fe9d6a3b --- /dev/null +++ b/internal/pkg/crawl/sitespecific/reddit/reddit.go @@ -0,0 +1,50 @@ +package reddit + +import ( + "net/http" + "strings" +) + +func IsRedditURL(req *http.Request) bool { + return strings.Contains(req.URL.Host, "reddit.com") +} + +func AddCookies(req *http.Request) { + newCookies := []http.Cookie{ + { + Name: "eu_cookie_v2", + Value: "3", + Domain: ".reddit.com", + Path: "/", + }, + { + Name: "over18", + Value: "1", + Domain: ".reddit.com", + Path: "/", + }, + { + Name: "options", + Value: "%7B%22pref_quarantine_optin%22%3A%20true%2C%20%22pref_gated_sr_optin%22%3A%20true%7D", + Domain: ".reddit.com", + Path: "/", + }, + } + + existingCookies := req.Cookies() + + for _, newCookie := range newCookies { + exists := false + for _, existingCookie := range existingCookies { + if existingCookie.Name == newCookie.Name && + existingCookie.Domain == newCookie.Domain && + existingCookie.Path == newCookie.Path { + exists = true + break + } + } + if !exists { + req.AddCookie(&newCookie) + } + } +}