diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/config.cr | 2 | ||||
| -rw-r--r-- | src/invidious/helpers/helpers.cr | 4 | ||||
| -rw-r--r-- | src/invidious/helpers/serialized_yt_data.cr | 70 | ||||
| -rw-r--r-- | src/invidious/playlists.cr | 37 | ||||
| -rw-r--r-- | src/invidious/routes/api/v1/authenticated.cr | 5 | ||||
| -rw-r--r-- | src/invidious/routes/api/v1/videos.cr | 2 | ||||
| -rw-r--r-- | src/invidious/routes/feeds.cr | 4 | ||||
| -rw-r--r-- | src/invidious/routes/images.cr | 250 | ||||
| -rw-r--r-- | src/invidious/routes/login.cr | 8 | ||||
| -rw-r--r-- | src/invidious/videos.cr | 17 | ||||
| -rw-r--r-- | src/invidious/yt_backend/connection_pool.cr | 33 | ||||
| -rw-r--r-- | src/invidious/yt_backend/youtube_api.cr | 13 |
12 files changed, 289 insertions, 156 deletions
diff --git a/src/invidious/config.cr b/src/invidious/config.cr index bacdb4ac..578e31fd 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -93,7 +93,7 @@ class Config property port : Int32 = 3000 # Port to listen for connections (overrided by command line argument) property host_binding : String = "0.0.0.0" # Host to bind (overrided by command line argument) property pool_size : Int32 = 100 # Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`) - property use_quic : Bool = true # Use quic transport for youtube api + property use_quic : Bool = false # Use quic transport for youtube api @[YAML::Field(converter: Preferences::StringToCookies)] property cookies : HTTP::Cookies = HTTP::Cookies.new # Saved cookies in "name1=value1; name2=value2..." format diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 9c053d74..c3b356a9 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -206,7 +206,7 @@ def create_notification_stream(env, topics, connection_channel) video = get_video(video_id, PG_DB) video.published = published - response = JSON.parse(video.to_json(locale)) + response = JSON.parse(video.to_json(locale, nil)) if fields_text = env.params.query["fields"]? begin @@ -282,7 +282,7 @@ def create_notification_stream(env, topics, connection_channel) video = get_video(video_id, PG_DB) video.published = Time.unix(published) - response = JSON.parse(video.to_json(locale)) + response = JSON.parse(video.to_json(locale, nil)) if fields_text = env.params.query["fields"]? begin diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr index 1ba3f20e..f92b7b89 100644 --- a/src/invidious/helpers/serialized_yt_data.cr +++ b/src/invidious/helpers/serialized_yt_data.cr @@ -58,17 +58,13 @@ struct SearchVideo end end - def to_xml(auto_generated, query_params, xml : XML::Builder | Nil = nil) - if xml - to_xml(HOST_URL, auto_generated, query_params, xml) - else - XML.build do |xml| - to_xml(HOST_URL, auto_generated, query_params, xml) - end + def to_xml(auto_generated, query_params, _xml : Nil) + XML.build do |xml| + to_xml(auto_generated, query_params, xml) end end - def to_json(locale : Hash(String, JSON::Any), json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "video" json.field "title", self.title @@ -99,16 +95,17 @@ struct SearchVideo end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + def to_json(json : JSON::Builder) + to_json(nil, json) + end + def is_upcoming premiere_timestamp ? true : false end @@ -133,7 +130,7 @@ struct SearchPlaylist property videos : Array(SearchPlaylistVideo) property thumbnail : String? - def to_json(locale, json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "playlist" json.field "title", self.title @@ -163,15 +160,16 @@ struct SearchPlaylist end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + + def to_json(json : JSON::Builder) + to_json(nil, json) + end end struct SearchChannel @@ -185,7 +183,7 @@ struct SearchChannel property description_html : String property auto_generated : Bool - def to_json(locale, json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "channel" json.field "author", self.author @@ -215,15 +213,16 @@ struct SearchChannel end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + + def to_json(json : JSON::Builder) + to_json(nil, json) + end end class Category @@ -235,7 +234,7 @@ class Category property description_html : String property badges : Array(Tuple(String, String))? - def to_json(locale, json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "category" json.field "title", self.title @@ -249,15 +248,16 @@ class Category end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + + def to_json(json : JSON::Builder) + to_json(nil, json) + end end alias SearchItem = SearchVideo | SearchChannel | SearchPlaylist | Category diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 443d19d7..f37667b5 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -11,7 +11,7 @@ struct PlaylistVideo property index : Int64 property live_now : Bool - def to_xml(auto_generated, xml : XML::Builder) + def to_xml(xml : XML::Builder) xml.element("entry") do xml.element("id") { xml.text "yt:video:#{self.id}" } xml.element("yt:videoId") { xml.text self.id } @@ -20,13 +20,8 @@ struct PlaylistVideo xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?v=#{self.id}") xml.element("author") do - if auto_generated - xml.element("name") { xml.text self.author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } - else - xml.element("name") { xml.text author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } - end + xml.element("name") { xml.text self.author } + xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } end xml.element("content", type: "xhtml") do @@ -47,17 +42,11 @@ struct PlaylistVideo end end - def to_xml(auto_generated, xml : XML::Builder? = nil) - if xml - to_xml(auto_generated, xml) - else - XML.build do |xml| - to_xml(auto_generated, xml) - end - end + def to_xml(_xml : Nil = nil) + XML.build { |xml| to_xml(xml) } end - def to_json(locale, json : JSON::Builder, index : Int32?) + def to_json(json : JSON::Builder, index : Int32? = nil) json.object do json.field "title", self.title json.field "videoId", self.id @@ -81,14 +70,8 @@ struct PlaylistVideo end end - def to_json(locale, json : JSON::Builder? = nil, index : Int32? = nil) - if json - to_json(locale, json, index: index) - else - JSON.build do |json| - to_json(locale, json, index: index) - end - end + def to_json(_json : Nil, index : Int32? = nil) + JSON.build { |json| to_json(json, index: index) } end end @@ -144,7 +127,7 @@ struct Playlist json.array do videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, video_id: video_id) videos.each do |video| - video.to_json(locale, json) + video.to_json(json) end end end @@ -224,7 +207,7 @@ struct InvidiousPlaylist videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, video_id: video_id) videos.each_with_index do |video, index| - video.to_json(locale, json, offset + index) + video.to_json(json, offset + index) end end end diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index 7950b302..cdd9e2f6 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -274,7 +274,10 @@ module Invidious::Routes::API::V1::Authenticated env.response.headers["Location"] = "#{HOST_URL}/api/v1/auth/playlists/#{plid}/videos/#{playlist_video.index.to_u64.to_s(16).upcase}" env.response.status_code = 201 - playlist_video.to_json(locale, index: playlist.index.size) + + JSON.build do |json| + playlist_video.to_json(json, index: playlist.index.size) + end end def self.delete_video_in_playlist(env) diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index d483bca6..1edee29c 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -16,7 +16,7 @@ module Invidious::Routes::API::V1::Videos return error_json(500, ex) end - video.to_json(locale) + video.to_json(locale, nil) end def self.captions(env) diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index 40c41dc1..f4a8467b 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -281,9 +281,7 @@ module Invidious::Routes::Feeds xml.element("name") { xml.text playlist.author } end - videos.each do |video| - video.to_xml(false, xml) - end + videos.each &.to_xml(xml) end end else diff --git a/src/invidious/routes/images.cr b/src/invidious/routes/images.cr index bb924cdf..594a7869 100644 --- a/src/invidious/routes/images.cr +++ b/src/invidious/routes/images.cr @@ -3,31 +3,61 @@ module Invidious::Routes::Images def self.ggpht(env) url = env.request.path.lchop("/ggpht") - headers = HTTP::Headers{":authority" => "yt3.ggpht.com"} + headers = ( + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + HTTP::Headers{":authority" => "yt3.ggpht.com"} + else + HTTP::Headers.new + end + {% else %} + HTTP::Headers.new + {% end %} + ) + REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? headers[header] = env.request.headers[header] end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + # We're encapsulating this into a proc in order to easily reuse this + # portion of the code for each request block below. + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Access-Control-Allow-Origin"] = "*" - - if response.status_code >= 300 - env.response.headers.delete("Transfer-Encoding") - break - end + env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) + if response.status_code >= 300 + env.response.headers.delete("Transfer-Encoding") + return end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end @@ -48,7 +78,9 @@ module Invidious::Routes::Images headers = HTTP::Headers.new - headers[":authority"] = "#{authority}.ytimg.com" + {% unless flag?(:disable_quic) %} + headers[":authority"] = "#{authority}.ytimg.com" + {% end %} REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? @@ -56,25 +88,41 @@ module Invidious::Routes::Images end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Connection"] = "close" - env.response.headers["Access-Control-Allow-Origin"] = "*" - - if response.status_code >= 300 - env.response.headers.delete("Transfer-Encoding") - break - end + env.response.headers["Connection"] = "close" + env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) + if response.status_code >= 300 + return env.response.headers.delete("Transfer-Encoding") end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end @@ -83,34 +131,60 @@ module Invidious::Routes::Images def self.s_p_image(env) id = env.params.url["id"] name = env.params.url["name"] - url = env.request.resource - headers = HTTP::Headers{":authority" => "i9.ytimg.com"} + headers = ( + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + HTTP::Headers{":authority" => "i9.ytimg.com"} + else + HTTP::Headers.new + end + {% else %} + HTTP::Headers.new + {% end %} + ) + REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? headers[header] = env.request.headers[header] end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Access-Control-Allow-Origin"] = "*" - - if response.status_code >= 300 && response.status_code != 404 - env.response.headers.delete("Transfer-Encoding") - break - end + env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) + if response.status_code >= 300 && response.status_code != 404 + return env.response.headers.delete("Transfer-Encoding") end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end @@ -149,16 +223,44 @@ module Invidious::Routes::Images id = env.params.url["id"] name = env.params.url["name"] - headers = HTTP::Headers{":authority" => "i.ytimg.com"} + headers = ( + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + HTTP::Headers{":authority" => "i.ytimg.com"} + else + HTTP::Headers.new + end + {% else %} + HTTP::Headers.new + {% end %} + ) if name == "maxres.jpg" build_thumbnails(id).each do |thumb| - if YT_POOL.client &.head("/vi/#{id}/#{thumb[:url]}.jpg", headers).status_code == 200 - name = thumb[:url] + ".jpg" - break - end + thumbnail_resource_path = "/vi/#{id}/#{thumb[:url]}.jpg" + # Logic here is short enough that manually typing them out should be fine. + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + if YT_POOL.client &.head(thumbnail_resource_path, headers).status_code == 200 + name = thumb[:url] + ".jpg" + break + end + else + if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200 + name = thumb[:url] + ".jpg" + break + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200 + name = thumb[:url] + ".jpg" + break + end + {% end %} end end + url = "/vi/#{id}/#{name}" REQUEST_HEADERS_WHITELIST.each do |header| @@ -167,24 +269,40 @@ module Invidious::Routes::Images end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Access-Control-Allow-Origin"] = "*" + env.response.headers["Access-Control-Allow-Origin"] = "*" - if response.status_code >= 300 && response.status_code != 404 - env.response.headers.delete("Transfer-Encoding") - break - end - - proxy_file(response, env) + if response.status_code >= 300 && response.status_code != 404 + return env.response.headers.delete("Transfer-Encoding") end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://i.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://i.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end diff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.cr index b719b571..562d88e5 100644 --- a/src/invidious/routes/login.cr +++ b/src/invidious/routes/login.cr @@ -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 begin - client = QUIC::Client.new(LOGIN_URL) + client = nil # Declare variable + {% unless flag?(:disable_quic) %} + client = CONFIG.use_quic ? QUIC::Client.new(LOGIN_URL) : HTTP::Client.new(LOGIN_URL) + {% else %} + client = HTTP::Client.new(LOGIN_URL) + {% end %} + headers = HTTP::Headers.new login_page = client.get("/ServiceLogin") diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index d38a66d8..d3e5800c 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -275,7 +275,7 @@ struct Video end end - def to_json(locale : Hash(String, JSON::Any), json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "video" @@ -474,14 +474,13 @@ struct Video end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json - to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end - end + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build { |json| to_json(locale, json) } + end + + def to_json(json : JSON::Builder | Nil = nil) + to_json(nil, json) end def title diff --git a/src/invidious/yt_backend/connection_pool.cr b/src/invidious/yt_backend/connection_pool.cr index 5ba2d73c..3feb9233 100644 --- a/src/invidious/yt_backend/connection_pool.cr +++ b/src/invidious/yt_backend/connection_pool.cr @@ -1,4 +1,10 @@ -require "lsquic" +{% unless flag?(:disable_quic) %} + require "lsquic" + + alias HTTPClientType = QUIC::Client | HTTP::Client +{% else %} + alias HTTPClientType = HTTP::Client +{% end %} 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" @@ -19,7 +25,7 @@ struct YoutubeConnectionPool property! url : URI property! capacity : Int32 property! timeout : Float64 - property pool : DB::Pool(QUIC::Client | HTTP::Client) + property pool : DB::Pool(HTTPClientType) def initialize(url : URI, @capacity = 5, @timeout = 5.0, use_quic = true) @url = url @@ -36,7 +42,12 @@ struct YoutubeConnectionPool response = yield conn rescue ex conn.close - conn = QUIC::Client.new(url) + {% unless flag?(:disable_quic) %} + conn = CONFIG.use_quic ? QUIC::Client.new(url) : HTTP::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 = Socket::Family::INET if conn.family == Socket::Family::UNSPEC conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com" @@ -50,12 +61,18 @@ struct YoutubeConnectionPool end 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 - if use_quic - conn = QUIC::Client.new(url) - else + DB::Pool(HTTPClientType).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 + conn = QUIC::Client.new(url) + else + conn = HTTP::Client.new(url) + end + {% else %} conn = HTTP::Client.new(url) - end + {% end %} + 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.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com" diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 8ab2fe46..27f25036 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -404,10 +404,19 @@ module YoutubeAPI url = "#{endpoint}?key=#{client_config.api_key}" headers = HTTP::Headers{ - "Content-Type" => "application/json; charset=UTF-8", - "Accept-Encoding" => "gzip", + "Content-Type" => "application/json; charset=UTF-8", } + # The normal HTTP client automatically applies accept-encoding: gzip, + # and decompresses. However, explicitly applying it will remove this functionality. + # + # https://github.com/crystal-lang/crystal/issues/11252#issuecomment-929594741 + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + headers["Accept-Encoding"] = "gzip" + end + {% end %} + # Logging LOGGER.debug("YoutubeAPI: Using endpoint: \"#{endpoint}\"") LOGGER.trace("YoutubeAPI: ClientConfig: #{client_config}") |
