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

Add headers option on Http download strategy #89

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

##### Enhancements

* None.
* Add `:headers` option to allow passing in custom headers to `cURL` when downloading source via the `:http` download strategy.
[Wilmar van Heerden](https://github.com/wilmarvh)
[cocoapods-downloader#89](https://github.com/CocoaPods/cocoapods-downloader/issues/89)
[#557](https://github.com/CocoaPods/Core/pull/557)

##### Bug Fixes

Expand Down
9 changes: 8 additions & 1 deletion lib/cocoapods-downloader/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ class Http < RemoteFile
executable :curl

def download_file(full_filename)
curl! '-f', '-L', '-o', full_filename, url, '--create-dirs', '--netrc-optional', '--retry', '2'
parameters = ['-f', '-L', '-o', full_filename, url, '--create-dirs', '--netrc-optional', '--retry', '2']

headers.each do |h|
parameters << '-H'
parameters << h
end unless headers.nil?

curl! parameters
wilmarvh marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/cocoapods-downloader/remote_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Pod
module Downloader
class RemoteFile < Base
def self.options
[:type, :flatten, :sha1, :sha256]
[:type, :flatten, :sha1, :sha256, :headers]
end

class UnsupportedFileTypeError < StandardError; end
Expand Down Expand Up @@ -35,6 +35,10 @@ def type
end
end

def headers
options[:headers]
end

# @note The archive is flattened if it contains only one folder and its
# extension is either `tgz`, `tar`, `tbz` or the options specify
# it.
Expand Down
38 changes: 38 additions & 0 deletions spec/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,44 @@ module Downloader
new_options = Downloader.preprocess_options(options)
new_options.should == options
end

it 'passes the correct default parameters to cURL' do
options = { :http => "#{@fixtures_url}/lib.zip" }
downloader = Downloader.for_target(tmp_folder, options)
downloader.expects(:curl!).with(
all_of(
includes('-f'),
includes('-L'),
includes('-o'),
includes('--create-dirs'),
includes('--netrc-optional'),
includes('--retry'),
includes('2'),
),
)
should.raise DownloaderError do
downloader.download
end
end

it 'passes the HTTP headers to cURL' do
options = {
:http => "#{@fixtures_url}/lib.zip",
:headers => ['Accept: application/json', 'Authorization: Bearer'],
}
downloader = Downloader.for_target(tmp_folder, options)
downloader.expects(:curl!).with(
all_of(
includes('-H'),
includes('Accept: application/json'),
includes('-H'),
includes('Authorization: Bearer'),
),
)
should.raise DownloaderError do
downloader.download
end
end
end
end
end