Skip to content

Commit

Permalink
use put_if_absent for assigning headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Nov 17, 2023
1 parent 86ee761 commit 20da0e5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/invidious/yt_backend/connection_pool.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
def add_yt_headers(request)
if request.headers["User-Agent"] == "Crystal"
request.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
end
request.headers.delete("User-Agent") if request.headers["User-Agent"] == "Crystal"
request.headers.put_if_absent("User-Agent") { "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" }

request.headers["Accept-Charset"] ||= "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
request.headers["Accept"] ||= "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
request.headers["Accept-Language"] ||= "en-us,en;q=0.5"
request.headers.put_if_absent("Accept-Charset") { "ISO-8859-1,utf-8;q=0.7,*;q=0.7" }
request.headers.put_if_absent("Accept") { "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }
request.headers.put_if_absent("Accept-Language") { "en-us,en;q=0.5" }

# Preserve original cookies and add new YT consent cookie for EU servers
request.headers["Cookie"] = "#{request.headers["cookie"]?}; CONSENT=PENDING+#{Random.rand(100..999)}"
Expand Down

0 comments on commit 20da0e5

Please sign in to comment.