mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-19 04:34:30 -05:00
Add compile-time flag to remove code for QUIC
This commit is contained in:
parent
a12571e748
commit
d379a36c0e
@ -53,7 +53,13 @@ module Invidious::Routes::Login
|
|||||||
|
|
||||||
# See https://github.com/ytdl-org/youtube-dl/blob/2019.04.07/youtube_dl/extractor/youtube.py#L82
|
# See https://github.com/ytdl-org/youtube-dl/blob/2019.04.07/youtube_dl/extractor/youtube.py#L82
|
||||||
begin
|
begin
|
||||||
|
client = nil # Declare variable
|
||||||
|
{% unless flag?(:disable_quic) %}
|
||||||
client = QUIC::Client.new(LOGIN_URL)
|
client = QUIC::Client.new(LOGIN_URL)
|
||||||
|
{% else %}
|
||||||
|
client = HTTP::Client.new(LOGIN_URL)
|
||||||
|
{% end %}
|
||||||
|
|
||||||
headers = HTTP::Headers.new
|
headers = HTTP::Headers.new
|
||||||
|
|
||||||
login_page = client.get("/ServiceLogin")
|
login_page = client.get("/ServiceLogin")
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
require "lsquic"
|
require "lsquic"
|
||||||
|
|
||||||
|
{% unless flag?(:disable_quic) %}
|
||||||
|
require "lsquic"
|
||||||
|
|
||||||
|
alias ConnectonClientType = QUIC::Client | HTTP::Client
|
||||||
|
{% else %}
|
||||||
|
alias ConnectonClientType = HTTP::Client
|
||||||
|
{% end %}
|
||||||
|
|
||||||
def add_yt_headers(request)
|
def add_yt_headers(request)
|
||||||
request.headers["user-agent"] ||= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
|
request.headers["user-agent"] ||= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
|
||||||
request.headers["accept-charset"] ||= "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
|
request.headers["accept-charset"] ||= "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
|
||||||
@ -19,7 +27,7 @@ struct YoutubeConnectionPool
|
|||||||
property! url : URI
|
property! url : URI
|
||||||
property! capacity : Int32
|
property! capacity : Int32
|
||||||
property! timeout : Float64
|
property! timeout : Float64
|
||||||
property pool : DB::Pool(QUIC::Client | HTTP::Client)
|
property pool : DB::Pool(ConnectonClientType)
|
||||||
|
|
||||||
def initialize(url : URI, @capacity = 5, @timeout = 5.0, use_quic = true)
|
def initialize(url : URI, @capacity = 5, @timeout = 5.0, use_quic = true)
|
||||||
@url = url
|
@url = url
|
||||||
@ -36,7 +44,12 @@ struct YoutubeConnectionPool
|
|||||||
response = yield conn
|
response = yield conn
|
||||||
rescue ex
|
rescue ex
|
||||||
conn.close
|
conn.close
|
||||||
|
{% unless flag?(:disable_quic) %}
|
||||||
conn = QUIC::Client.new(url)
|
conn = QUIC::Client.new(url)
|
||||||
|
{% else %}
|
||||||
|
conn = HTTP::Client.new(url)
|
||||||
|
{% end %}
|
||||||
|
|
||||||
conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET
|
conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET
|
||||||
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
|
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
|
||||||
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
||||||
@ -50,12 +63,18 @@ struct YoutubeConnectionPool
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def build_pool(use_quic)
|
private def build_pool(use_quic)
|
||||||
DB::Pool(QUIC::Client | HTTP::Client).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do
|
DB::Pool(ConnectonClientType).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do
|
||||||
|
conn = nil # Declare
|
||||||
|
{% unless flag?(:disable_quic) %}
|
||||||
if use_quic
|
if use_quic
|
||||||
conn = QUIC::Client.new(url)
|
conn = QUIC::Client.new(url)
|
||||||
else
|
else
|
||||||
conn = HTTP::Client.new(url)
|
conn = HTTP::Client.new(url)
|
||||||
end
|
end
|
||||||
|
{% else %}
|
||||||
|
conn = HTTP::Client.new(url)
|
||||||
|
{% end %}
|
||||||
|
|
||||||
conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET
|
conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET
|
||||||
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
|
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
|
||||||
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
|
||||||
|
Loading…
Reference in New Issue
Block a user