136 Commits

Author SHA1 Message Date
Sam Ford
94449d07c0
parse_curl_response: Handle duplicate headers
`Curl#parse_curl_response` only includes the last instance of a given
header in its `:headers` hash (replicating pre-existing behavior).
This is a problem for headers like `Set-Cookie`, which can appear more
than once in a response.

This commit addresses the issue by collecting duplicate headers into
an array instead. Headers that only appear once in the response will
still have a string value but headers that appear more than once will
be an array of strings. Whenever headers from `#parse_curl_response`
are used (directly or indirectly), it's important to conditionally
handle the expected types.
2022-05-06 10:51:22 -04:00
Alexander Bayandin
6643f58b49
utils/curl: get encoding from header 2022-05-04 00:13:56 +01:00
Alexander Bayandin
4575ddf909
utils/curl: force utf-8 encoding for text content 2022-05-02 13:57:51 +01:00
Sam Ford
b7a4360433
#parse_curl_output: increase default max_iterations
The `max_iterations` value in `#parse_curl_output` is only intended
to prevent its `while` loop from potentially turning into an endless
loop. This should only come into play in exceptional circumstances
but the current default value (5) is low enough that we're seeing it
under normal circumstances.

`#parse_curl_output` isn't intended to restrict the number of
redirections (this should be done using the `--max-redirs` option in
`curl) but it's effectively doing this in rare cases due to the low
`max_iterations` default. This is a problem because `curl` can
successfully return a response only to have `#parse_curl_output`
error in relation to `max_iterations`.

Originally the code in `#parse_curl_output` was used in the context
of livecheck, where it's not a huge issue if a check fails. However,
now the `#parse_curl_output` method is used in important parts of
brew like `#curl_download`. We've received a report of a download
failing with the "Too many redirects (max = 5)` error, effectively
preventing the user from installing a formula [from a third-party
tap].

Until we can come up with a more adaptive way of bounding this
`while` loop, I think we should simply raise the default to something
that's less likely to be encountered under normal circumstances
(e.g., 25).
2022-04-26 15:49:02 -04:00
Alexander Bayandin
c726385035
utils/curl: fix headers check for protected urls 2022-04-26 13:27:42 +01:00
Sam Ford
d6202384d7
Curl: Remove guard from certain parsing logic
The `#curl_http_content_headers_and_checksum` method previously
parsed responses from `curl` output even if `status.success?` wasn't
`true`. A recent commit of mine moved the parsing logic behind this
guard but it's now leading to a "...is not reachable" error when a URL
involves a large download that takes longer than 25 seconds to finish
and hits the timeout.

This commit resolves the issue for the time being by moving related
logic back to its previous location, where it isn't guarded by
`status.success?`.
2022-04-26 01:22:20 -04:00
Sam Ford
6bd2c831cd
Merge pull request #13181 from samford/livecheck/add-max-redirs-curl-arg
`Strategy`: Add `--max-redirs` to `DEFAULT_CURL_ARGS`
2022-04-25 14:25:36 -04:00
Sam Ford
3f7d9f82fc
#curl_download: default try_partial to false
When its `try_partial` argument is `true`, `#curl_download` makes a
`HEAD` request before downloading the file using `#curl`. Currently
`try_partial` defaults to `true`, so any `#curl_download` call that
doesn't explicitly specify `try_partial: false` will make a `HEAD`
request first. This can potentially involve several requests if the
URL redirects, so it can be a bit of unnecessary overhead when a
partial download isn't needed.

Partial downloads are generally only useful when we're working with
larger files, however there's currently only one place in brew where
`#curl_download` is used and this is the case:
`CurlDownloadStrategy`. The other `#curl_download` calls are fetching
smaller [text] files and don't need to support partial downloads.

This commit changes the default `try_partial` value to `false`,
making partial downloads opt-in rather than opt-out.

We want `try_partial` to continue to default to `true` in
`CurlDownloadStrategy` and there are various ways to accomplish this.
In this commit, I've chosen to update its `#initialize` method to
accept a `try_partial` argument that defaults to `true`, as this
value can also be used in classes that inherit from
`CurlDownloadStrategy` (e.g., `HomebrewCurlDownloadStrategy`). This
instance variable is passed to `#curl_download` in related methods,
effectively maintaining the previous `try_partial: true` value, while
also allowing this value to be overridden when necessary.

Other uses of `#curl_download` in brew are
`Formulary::FromUrlLoader#load_file` and
`Cask::CaskLoader::FromURILoader#load`, which did not provide a
`try_partial` argument but should have been using
`try_partial: false`. With the `try_partial: false` default in this
commit, these calls are now fine without a `try_partial` argument.

The only other use of `#curl_download` in brew is
`SPDX#download_latest_license_data!`. These calls were previously
using `try_partial: false` but we can now omit this argument with
the new `false` default (aligning with the above).
2022-04-22 14:23:08 -04:00
Sam Ford
2722fbe30e
#parse_curl_output: add max_iterations parameter
In cases where there may be more than five responses in `curl`
output to parse, we need to be able to control the `max_iterations`
of the `while` loop in `#parse_curl_output` to properly parse all
the responses.

For example, if we pass `--max-redirs 5` to `curl` and there are
exactly five redirections before the final response, the output would
contain a total of six responses and `#parse_curl_output` wouldn't
properly handle this (it would give a `Too many redirects` error).
`max_iterations` should be the maximum number of redirections + 1
(to account for any final response after the redirections), so we
need to be able to override this value when necessary.
2022-04-22 13:17:45 -04:00
Sam Ford
c5eeff941e
Curl: Update to use response parsing methods 2022-04-20 23:47:51 -04:00
Sam Ford
9171eb2e16
Curl: Add methods to parse response 2022-04-20 23:47:51 -04:00
EricFromCanada
c952ea7358
bump: fix tests 2021-10-25 15:55:11 -04:00
Bo Anderson
2d539bc6af
utils/curl: don't use --cookie-jar to enable cookie engine
Fixes #12293.
2021-10-21 22:52:20 +01:00
EricFromCanada
811d0fa0bd
bump: add option to retrieve a subset of results
Plus a few fixes for output.
2021-10-19 20:14:39 -04:00
Bevan Kay
70ac4d70d2
audit: extend cloudflare https audit exception regex 2021-10-11 15:52:37 +11:00
Carlo Cabrera
7dabb465b3
system_config: don't print path to curl shim
See discussion at #12191.
2021-10-06 23:58:04 +08:00
Bo Anderson
03a72760ef
utils/curl: add comment detailing options handling 2021-10-05 13:24:29 +01:00
Bo Anderson
c6cddacc5e
utils/curl: fix false flag handling 2021-10-04 18:17:00 +01:00
Bo Anderson
73a1ff82d2
utils/curl: fix flag handling 2021-10-04 17:44:51 +01:00
Bo Anderson
ebc0783c5f
Merge pull request #12167 from Bo98/brewed-curl-old-macos
Install and use Homebrew's `ca-certificates` on macOS <= 10.15.5
2021-10-04 05:29:57 +01:00
Bo Anderson
30b24cf4ad
Use HOMEBREW_CURL universally, including formulae 2021-10-04 02:03:04 +01:00
Bo Anderson
1952d27ba2
Install and use Homebrew's ca-certificates on macOS <= 10.15.5 2021-10-03 17:52:10 +01:00
Sam Ford
f88966a8a5
Use curl options where appropriate 2021-09-07 14:13:19 -04:00
Sam Ford
d44979fa67
Curl#curl_args: Fix and refactor options 2021-09-07 14:13:17 -04:00
FnControlOption
7d0a36752b curl: echo any cookies received on a redirect 2021-09-01 06:32:30 -07:00
Michka Popoff
07df4a7e70
Use Homebrew curl for audit and fetch when specified in the formula
Introduce new :using for urls
2021-08-17 13:35:55 +02:00
Connor Mann
a079ba9bb3 Add parentheses for clarity 2021-05-14 15:28:56 -04:00
Connor Mann
2a9540b3ab
Check for key explicitly with key?
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2021-05-14 15:16:37 -04:00
Connor Mann
b546960da9 Revert "Update Library/Homebrew/utils/curl.rb"
This reverts commit ecaaafba203578498fbc0a48493adea1790839f2.
2021-05-14 15:14:56 -04:00
Connor Mann
f7fe111430
Use blank? instead of checking for nil 2021-05-14 11:53:49 -04:00
Connor Mann
2500b8daba
Update Library/Homebrew/utils/curl.rb
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2021-05-14 11:47:38 -04:00
Connor Mann
ecaaafba20
Update Library/Homebrew/utils/curl.rb
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2021-05-14 11:16:35 -04:00
Connor Mann
b79aeab8b2
Update Library/Homebrew/utils/curl.rb
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2021-05-14 09:55:45 -04:00
Connor Mann
85702dfe53
Update Library/Homebrew/utils/curl.rb
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2021-05-14 09:55:40 -04:00
cnnrmnn
86bce7bf1d Stop unnecessarily dumping headers 2021-05-14 09:50:57 -04:00
cnnrmnn
a156621297 Simplify header parsing 2021-05-14 09:44:05 -04:00
cnnrmnn
16e7072543 Fix argument order 2021-05-13 12:53:57 -04:00
cnnrmnn
7637fd5366 Only use continue-at with partial requests 2021-05-13 12:28:34 -04:00
cnnrmnn
df0915e33f Check partial request support with Accept-Ranges 2021-05-13 12:11:34 -04:00
cnnrmnn
b9b917756c Add header parsing 2021-05-13 11:42:28 -04:00
cnnrmnn
aa989bd55a Change inititial partial request to HEAD request 2021-05-13 11:39:59 -04:00
Mike McQuaid
d81b898117
utils/curl: tweak style. 2021-04-22 13:57:28 +01:00
Kenneth Chew
af594739dc
audit: specify which URL has a content problem in problem message 2021-04-22 13:52:18 +01:00
Markus Reiter
cdcd216237
Revert "Revert "Merge pull request #10898 from reitermarkus/audit-timeout""
This reverts commit 0b8a9bc1a14d8513ab57423fe028d72a52b38b3d.
2021-04-03 20:10:33 +02:00
Markus Reiter
24c9b599a6
Revert "Revert "Merge pull request #10864 from reitermarkus/command-timeout""
This reverts commit 57b2660cae8cf43efd2b88d84a7174706328c001.
2021-04-03 20:10:32 +02:00
Rylan Polster
57b2660cae
Revert "Merge pull request #10864 from reitermarkus/command-timeout"
This reverts commit d55bdd3ddbe7ff2b1f106a41bd994dc117ca5142, reversing
changes made to 3c3bf1c74d1d7ef1d2c792719574623b6c3c4d25.
2021-03-24 01:22:18 -04:00
Rylan Polster
0b8a9bc1a1
Revert "Merge pull request #10898 from reitermarkus/audit-timeout"
This reverts commit 6eaeba184bee5ad42269819c362ab18e9c70b3fa, reversing
changes made to 28b176567992f8d323d73a0a1367d8239e34e8a4.
2021-03-24 01:22:03 -04:00
Markus Reiter
169d8aca4c Only raise Timeout::Error if timeout is specified. 2021-03-22 04:15:06 +01:00
Markus Reiter
7ad85116ef Ignore timeout when checking for HTTPS availability. 2021-03-22 03:34:35 +01:00
Markus Reiter
712a95fdd0 Allow specifying timeouts for commands and downloads. 2021-03-16 18:15:21 +01:00