Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use make_client instead of calling HTTP::Client #4709

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

syeopite
Copy link
Member

This PR is mostly so that we can customize the client Invidious uses for all HTTP requests. For example, to config a HTTP proxy to use.

I left images.cr untouched as to not conflict with #4326

Using `make_client` to create `HTTP::Client`, allows for a simple way to
easily add logic to all `HTTP::Client` initialized within Invidious.
@syeopite syeopite requested a review from a team as a code owner May 22, 2024 20:13
@syeopite syeopite requested review from unixfox and removed request for a team May 22, 2024 20:13
@@ -45,24 +42,22 @@ struct YoutubeConnectionPool

private def build_pool
DB::Pool(HTTP::Client).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do
conn = HTTP::Client.new(url)
conn.family = CONFIG.force_resolve
conn = make_client(url, force_resolve = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be that, btw:

Suggested change
conn = make_client(url, force_resolve = true)
conn = make_client(url, force_resolve: true)

I don't understand why the = isn't flagged by the compiler as invalid syntax.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, from a quick discussion in the Crystal matrix room, doing

make_client(url, foo = true)

is the same as doing

foo = true
make_client(url, foo)

i.e it assigns the value to a local variable and then passes that variable as a positional function parameter. In this case, this would be end up being assigned to region.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops thanks!

I guess that also explains why this wasn't caught my the CI #4709 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! I've opened an issue at the Crystal bug tracker, because it seems like something that shouldn't be allowed by design: crystal-lang/crystal#14722

Co-authored-by: Samantaz Fox <[email protected]>
@syeopite syeopite mentioned this pull request Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants