mirror of
https://github.com/iv-org/invidious.git
synced 2025-04-25 16:16:26 +00:00
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
This commit is contained in:
parent
cdb6eef055
commit
a3864e6691
@ -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 %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user