Skip to content

Commit

Permalink
curl: handle multiple Content-Type headers
Browse files Browse the repository at this point in the history
`#curl_http_content_headers_and_checksum` contains code that works
with a `Content-Type` header in a response but it expects there to
always be only one header in the response. This is normally a
reasonable assumption but we've come across a server that is giving
a response with multiple `Content-Type` headers in the response, so
this produces an error and causes `brew audit` to fail when checking
the URL.

This works around the issue by naively using the last `Content-Type`
header in the response when there's more than one. It's not something
that should normally occur but this will handle the situation when it
does.
  • Loading branch information
samford committed Oct 19, 2024
1 parent 6f17b06 commit 4ed2eb6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,15 @@ def curl_http_content_headers_and_checksum(

if status.success?
open_args = {}
content_type = headers["content-type"]

Check warning on line 470 in Library/Homebrew/utils/curl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/curl.rb#L470

Added line #L470 was not covered by tests

# Use the last `Content-Type` header if there is more than one instance
# in the response
content_type = content_type.last if content_type.is_a?(Array)

# Try to get encoding from Content-Type header
# TODO: add guessing encoding by <meta http-equiv="Content-Type" ...> tag
if (content_type = headers["content-type"]) &&
if content_type &&
(match = content_type.match(/;\s*charset\s*=\s*([^\s]+)/)) &&
(charset = match[1])
begin
Expand Down

0 comments on commit 4ed2eb6

Please sign in to comment.