From bdeb325bad15ea32a3f039de39418a88a6ab6180 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 26 Oct 2019 11:43:28 -0400 Subject: [PATCH] Fix monkeypatch for HTTP::Client --- src/invidious.cr | 2 +- src/invidious/helpers/handlers.cr | 4 ++-- src/invidious/helpers/utils.cr | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index cd6775a7..b0447865 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -5446,7 +5446,7 @@ get "/videoplayback" do |env| client = make_client(URI.parse(host), region) - response = HTTP::Client::Response.new(403) + response = HTTP::Client::Response.new(500) 5.times do begin response = client.head(url, headers) diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr index a3dfd062..5b60c1be 100644 --- a/src/invidious/helpers/handlers.cr +++ b/src/invidious/helpers/handlers.cr @@ -226,15 +226,15 @@ end class HTTP::Client private def handle_response(response) - if @socket.is_a?(OpenSSL::SSL::Socket::Client) + if @socket.is_a?(OpenSSL::SSL::Socket::Client) && @host.ends_with? "googlevideo.com" close unless response.keep_alive? || @socket.as(OpenSSL::SSL::Socket::Client).@in_buffer_rem.empty? + if @socket.as(OpenSSL::SSL::Socket::Client).@in_buffer_rem.empty? @socket = nil end else close unless response.keep_alive? end - response end end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 8d4eff9b..7dd1adf3 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -1610,7 +1610,11 @@ struct HTTPPool end response = yield conn - conn.unset_proxy + + if region + conn.unset_proxy + end + response rescue ex conn = HTTPClient.new(url)