From a3864e6691189dc2746eedbbf0029d1ff31bf054 Mon Sep 17 00:00:00 2001 From: syeopite Date: Wed, 9 Apr 2025 16:50:00 -0700 Subject: [PATCH] Use non-streaming api when not invoked with block Defaulting to the streaming api of `HTTP::Client` causes some issues since the streaming respone content needs to be accessed through #body_io rather than #body --- src/invidious/connection/pool.cr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/invidious/connection/pool.cr b/src/invidious/connection/pool.cr index 4107ceae..34ce49e2 100644 --- a/src/invidious/connection/pool.cr +++ b/src/invidious/connection/pool.cr @@ -29,6 +29,8 @@ module Invidious::ConnectionPool abstract def pool : DB::Pool(PoolClient) {% for method in %w[get post put patch delete head options] %} + # Streaming API for {{method.id.upcase}} request. + # The response will have its body as an `IO` accessed via `HTTP::Client::Response#body_io`. def {{method.id}}(*args, **kwargs, &) self.client do | client | client.{{method.id}}(*args, **kwargs) do | response | @@ -42,11 +44,11 @@ module Invidious::ConnectionPool end end + # Executes a {{method.id.upcase}} request. + # The response will have its body as a `String`, accessed via `HTTP::Client::Response#body`. def {{method.id}}(*args, **kwargs) - {{method.id}}(*args, **kwargs) do | response | - return response - ensure - response.body_io?.try &. skip_to_end + self.client do | client | + return client.{{method.id}}(*args, **kwargs) end end {% end %}