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 7 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

@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

syeopite and others added 7 commits August 24, 2024 19:34
Using `make_client` to create `HTTP::Client`, allows for a simple way to
easily add logic to all `HTTP::Client` initialized within Invidious.
Co-authored-by: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com>
Co-authored-by: Samantaz Fox <coding@samantaz.fr>
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
next make_client(url, force_resolve: true)
Copy link
Member Author

Choose a reason for hiding this comment

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

This line fails Ameba's Style/RedundantNext rule.

Should it also be disabled like Style/RedundantBegin and Style/RedundantReturn?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't know that next could be used like that! And yes, this will make the syntax consistent with the rest.

@SamantazFox SamantazFox added the need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants