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

Cask::Audit: Align user agents with livecheck #17512

Conversation

samford
Copy link
Member

@samford samford commented Jun 14, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

The #page_headers and #page_content methods in Livecheck::Strategy will fetch a URL using our default user agent but if the request fails it will retry with the :browser user agent. [For context, it was added as an interim measure to make URLs work that require a different user agent but I aim to remove it in the future in favor of specifying the user agent in a livecheck block (so we don't make unnecessary requests that we know will fail).]

Cask::Audit#audit_livecheck_https_availability checks the livecheck block URL but it only does so using our default user agent (i.e., it calls #validate_url_for_https_availability which calls Utils::Curl#curl_check_http_content which has a user_agents: [:default] parameter). Due to this behavioral mismatch, it's possible for a livecheck block to work but for this cask audit to fail.

This addresses the issue by adding user_agents: [:default, :browser] to the arguments the audit uses, which aligns its behavior with livecheck's.


I know there's some discussion in #15350 around whether we should be switching user agents at all and I'll reply to that issue to further the discussion. In the interim time, this PR is simply about aligning existing behavior, so PRs like Homebrew/homebrew-cask#175619 will correctly pass.

The `#page_headers` and `#page_content` methods in
`Livecheck::Strategy` will fetch a URL using our default user agent
but if the request fails it will retry with the `:browser` user agent.
[For context, it was added as an interim measure to make URLs work
that require a different user agent but I aim to remove it in the
future in favor of specifying the user agent in a `livecheck` block
(so we don't make unnecessary requests that we know will fail).]

`Cask::Audit#audit_livecheck_https_availability` checks the
`livecheck` block URL but it only does so using our default user
agent (i.e., it calls `#validate_url_for_https_availability` which
calls `Utils::Curl#curl_check_http_content` which has a `user_agents:
[:default]` parameter). Due to this behavioral mismatch, it's possible
for a `livecheck` block to work but for this cask audit to fail.

This addresses the issue by adding `user_agents: [:default, :browser]`
to the arguments the audit uses, which aligns its behavior with
livecheck's.
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Fine with me as an interim PR. Thanks @samford!

@MikeMcQuaid MikeMcQuaid merged commit e2d0158 into Homebrew:master Jun 15, 2024
25 checks passed
@samford samford deleted the cask-audit-livecheck-availability-user-agents branch June 15, 2024 17:32
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.

2 participants