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

Don't assume all responses have headers #607

Merged
merged 1 commit into from
Jan 30, 2020
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

##### Bug Fixes

* None.
* Fix a crash when an HTTP(S) response has no headers
[Eric Amorde](https://github.com/amorde)
[#607](https://github.com/CocoaPods/Core/pull/607)


## 1.9.0.beta.2 (2019-12-17)
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-core/cdn_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def download_and_save_with_retries_async(partial_url, file_remote_url, etag, ret
when 200
File.open(path, 'w') { |f| f.write(response.response_body) }

etag_new = response.headers['etag']
etag_new = response.headers['etag'] unless response.headers.nil?
debug "CDN: #{name} Relative path downloaded: #{partial_url}, save ETag: #{etag_new}"
File.open(etag_path, 'w') { |f| f.write(etag_new) } unless etag_new.nil?
partial_url
Expand Down
12 changes: 12 additions & 0 deletions spec/cdn_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ def typhoeus_non_http_response_future(code)
@source.versions('BeaconKit').map(&:to_s).should == %w(1.0.0)
end

it 'handles responses with no headers' do
@source.expects(:download_typhoeus_impl_async).
with_url('http://localhost:4321/all_pods_versions_2_0_9.txt').
returns(typhoeus_http_response_future(200, nil, 'BeaconKit/1.0.0'))
@source.expects(:download_typhoeus_impl_async).
with_url('http://localhost:4321/Specs/2/0/9/BeaconKit/1.0.0/BeaconKit.podspec.json').
returns(typhoeus_http_response_future(200, nil, '{}'))
should.not.raise do
@source.versions('BeaconKit')
end
end

it 'raises if unexpected HTTP error' do
@source.expects(:download_typhoeus_impl_async).
returns(typhoeus_http_response_future(500))
Expand Down