aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dev-cmd
diff options
context:
space:
mode:
authorMike McQuaid2017-02-23 09:09:58 +0000
committerMike McQuaid2017-02-23 09:09:58 +0000
commit5e9057500419d1a2b41efe784e9f12ae232e7f6e (patch)
tree4e8b9c3f4f432de97a5a4f38ec5aee1c2bcdf32d /Library/Homebrew/dev-cmd
parent5390897883f11fe2257e57bd5547cb1bbb144fb0 (diff)
downloadbrew-5e9057500419d1a2b41efe784e9f12ae232e7f6e.tar.bz2
audit: handle redirects in get_content_details.
Diffstat (limited to 'Library/Homebrew/dev-cmd')
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index aa9dd775a..493f1eb09 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -1542,12 +1542,16 @@ class ResourceAuditor
def get_content_details(url)
out = {}
output, = curl_output "--connect-timeout", "15", "--include", url
- split = output.partition("\r\n\r\n")
- headers = split.first
- out[:status] = headers[%r{HTTP\/.* (\d+)}, 1]
+ status_code = :unknown
+ while status_code == :unknown || status_code.to_s.start_with?("3")
+ headers, _, output = output.partition("\r\n\r\n")
+ status_code = headers[%r{HTTP\/.* (\d+)}, 1]
+ end
+
+ out[:status] = status_code
out[:etag] = headers[%r{ETag: ([wW]\/)?"(([^"]|\\")*)"}, 2]
out[:content_length] = headers[/Content-Length: (\d+)/, 1]
- out[:file_hash] = Digest::SHA256.digest split.last
+ out[:file_hash] = Digest::SHA256.digest output
out
end
end