diff options
| author | Omar Roth <omarroth@protonmail.com> | 2019-11-28 08:19:28 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2019-11-28 08:19:28 -0600 |
| commit | a017574f74665edc9645b9e1c0414e0a34e13f41 (patch) | |
| tree | d0f6042a1f321a6b83457b7fa9674b4cd10b0a7b | |
| parent | 3fea1976c835ecd181bbf4c2ca02ee88d61370a1 (diff) | |
| download | invidious-a017574f74665edc9645b9e1c0414e0a34e13f41.tar.gz invidious-a017574f74665edc9645b9e1c0414e0a34e13f41.tar.bz2 invidious-a017574f74665edc9645b9e1c0414e0a34e13f41.zip | |
Add support for force_resolve to QUIC client
| -rw-r--r-- | shard.yml | 2 | ||||
| -rw-r--r-- | src/invidious.cr | 9 | ||||
| -rw-r--r-- | src/invidious/helpers/utils.cr | 12 |
3 files changed, 14 insertions, 9 deletions
@@ -26,7 +26,7 @@ dependencies: version: ~> 0.1.2 lsquic: github: omarroth/lsquic.cr - version: ~> 0.1.5 + version: ~> 0.1.7 crystal: 0.31.1 diff --git a/src/invidious.cr b/src/invidious.cr index 147fe935..59590f22 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -4523,10 +4523,11 @@ get "/api/v1/search/suggestions" do |env| query ||= "" begin - response = QUIC::Client.get( - "https://suggestqueries.google.com/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback" - ).body - + client = QUIC::Client.new("suggestqueries.google.com") + client.family = CONFIG.force_resolve || Socket::Family::INET + client.family = Socket::Family::INET if client.family == Socket::Family::UNSPEC + response = client.get("/complete/search?hl=en&gl=#{region}&client=youtube&ds=yt&q=#{URI.encode_www_form(query)}&callback=suggestCallback").body + body = response[35..-2] body = JSON.parse(body).as_a suggestions = body[1].as_a[0..-2] diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 53c18dd5..6fcfa8d2 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -31,8 +31,10 @@ struct QUICPool begin response = yield conn rescue ex - conn.destroy_engine + conn.close conn = QUIC::Client.new(url) + 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" response = yield conn ensure @@ -45,9 +47,11 @@ struct QUICPool private def build_pool ConnectionPool(QUIC::Client).new(capacity: capacity, timeout: timeout) do - client = QUIC::Client.new(url) - client.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com" - client + conn = QUIC::Client.new(url) + 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" + conn end end end |
