Merge pull request #4593 from reitermarkus/curl-options
Merge `curl` options used by casks into download strategies.
This commit is contained in:
commit
3a99e64646
@ -263,14 +263,29 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
|
|
||||||
# Curl options to be always passed to curl,
|
# Curl options to be always passed to curl,
|
||||||
# with raw head calls (`curl --head`) or with actual `fetch`.
|
# with raw head calls (`curl --head`) or with actual `fetch`.
|
||||||
|
def _curl_args
|
||||||
|
args = []
|
||||||
|
|
||||||
|
if meta.key?(:cookies)
|
||||||
|
escape_cookie = ->(cookie) { URI.encode_www_form([cookie]) }
|
||||||
|
args += ["-b", meta.fetch(:cookies).map(&escape_cookie).join(";")]
|
||||||
|
end
|
||||||
|
|
||||||
|
args += ["-e", meta.fetch(:referer)] if meta.key?(:referer)
|
||||||
|
|
||||||
|
args += ["--user", meta.fetch(:user)] if meta.key?(:user)
|
||||||
|
|
||||||
|
args
|
||||||
|
end
|
||||||
|
|
||||||
def _curl_opts
|
def _curl_opts
|
||||||
return ["--user", meta.fetch(:user)] if meta.key?(:user)
|
return { user_agent: meta.fetch(:user_agent) } if meta.key?(:user_agent)
|
||||||
[]
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_url(url)
|
def resolved_url(url)
|
||||||
redirect_url, _, status = curl_output(
|
redirect_url, _, status = curl_output(
|
||||||
*_curl_opts, "--silent", "--head",
|
"--silent", "--head",
|
||||||
"--write-out", "%{redirect_url}",
|
"--write-out", "%{redirect_url}",
|
||||||
"--output", "/dev/null",
|
"--output", "/dev/null",
|
||||||
url.to_s
|
url.to_s
|
||||||
@ -289,17 +304,20 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
redirect_url
|
redirect_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def curl_output(*args, **options)
|
||||||
|
super(*_curl_args, *args, **_curl_opts, **options)
|
||||||
|
end
|
||||||
|
|
||||||
def curl(*args, **options)
|
def curl(*args, **options)
|
||||||
args.concat _curl_opts
|
|
||||||
args << "--connect-timeout" << "5" unless mirrors.empty?
|
args << "--connect-timeout" << "5" unless mirrors.empty?
|
||||||
super(*args, **options)
|
super(*_curl_args, *args, **_curl_opts, **options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Detect and download from Apache Mirror
|
# Detect and download from Apache Mirror
|
||||||
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
||||||
def apache_mirrors
|
def apache_mirrors
|
||||||
mirrors, = curl_output(*_curl_opts, "--silent", "--location", "#{@url}&asjson=1")
|
mirrors, = curl_output("--silent", "--location", "#{@url}&asjson=1")
|
||||||
JSON.parse(mirrors)
|
JSON.parse(mirrors)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -323,7 +341,13 @@ end
|
|||||||
# Query parameters on the URL are converted into POST parameters
|
# Query parameters on the URL are converted into POST parameters
|
||||||
class CurlPostDownloadStrategy < CurlDownloadStrategy
|
class CurlPostDownloadStrategy < CurlDownloadStrategy
|
||||||
def _fetch
|
def _fetch
|
||||||
base_url, data = @url.split("?")
|
base_url, data = if meta.key?(:data)
|
||||||
|
escape_data = ->(d) { ["-d", URI.encode_www_form([d])] }
|
||||||
|
[@url, meta[:data].flat_map(&escape_data)]
|
||||||
|
else
|
||||||
|
@url.split("?", 2)
|
||||||
|
end
|
||||||
|
|
||||||
curl_download base_url, "--data", data, to: temporary_path
|
curl_download base_url, "--data", data, to: temporary_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -584,11 +608,19 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
|
|||||||
# This saves on bandwidth and will have a similar effect to verifying the
|
# This saves on bandwidth and will have a similar effect to verifying the
|
||||||
# cache as it will make any changes to get the right revision.
|
# cache as it will make any changes to get the right revision.
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
if revision
|
if revision
|
||||||
ohai "Checking out #{@ref}"
|
ohai "Checking out #{@ref}"
|
||||||
args << "-r" << revision
|
args << "-r" << revision
|
||||||
end
|
end
|
||||||
|
|
||||||
args << "--ignore-externals" if ignore_externals
|
args << "--ignore-externals" if ignore_externals
|
||||||
|
|
||||||
|
if meta[:trust_cert] == true
|
||||||
|
args << "--trust-server-cert"
|
||||||
|
args << "--non-interactive"
|
||||||
|
end
|
||||||
|
|
||||||
if target.directory?
|
if target.directory?
|
||||||
system_command("svn", args: ["update", *args], chdir: target.to_s)
|
system_command("svn", args: ["update", *args], chdir: target.to_s)
|
||||||
else
|
else
|
||||||
|
|||||||
@ -231,7 +231,7 @@ describe CurlDownloadStrategy do
|
|||||||
let(:specs) { { user: "download:123456" } }
|
let(:specs) { { user: "download:123456" } }
|
||||||
|
|
||||||
it "parses the opts and sets the corresponding args" do
|
it "parses the opts and sets the corresponding args" do
|
||||||
expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"])
|
expect(subject.send(:_curl_args)).to eq(["--user", "download:123456"])
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#tarball_path" do
|
describe "#tarball_path" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user