Skip to content

Commit

Permalink
Merge pull request #18596 from Homebrew/handle-multiple-content-type-…
Browse files Browse the repository at this point in the history
…headers

curl: handle multiple Content-Type headers
  • Loading branch information
MikeMcQuaid authored Oct 20, 2024
2 parents 6f17b06 + 4ed2eb6 commit d0ab3d3
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"]

# 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 d0ab3d3

Please sign in to comment.