Skip to content

Commit

Permalink
add: reddit custom code to add cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Aug 21, 2024
1 parent eb8a35c commit 2893638
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions internal/pkg/crawl/sitespecific/reddit/reddit.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 2893638

Please sign in to comment.