utils/curl: workaround curl bug for --head --request GET
				
					
				
			The `curl --head --request GET` causes a full download to happen on `curl` from 8.7.0 to 8.9.1[^1] which causes poor UX due to slow Cask downloads that can take almost twice as long as they should. [^1]: https://github.com/Homebrew/brew/issues/18213
This commit is contained in:
		
							parent
							
								
									1e29665e62
								
							
						
					
					
						commit
						43ee408793
					
				@ -27,6 +27,8 @@ RSpec.describe CurlGitHubPackagesDownloadStrategy do
 | 
			
		||||
    before do
 | 
			
		||||
      stub_const("HOMEBREW_GITHUB_PACKAGES_AUTH", authorization) if authorization.present?
 | 
			
		||||
 | 
			
		||||
      allow(strategy).to receive(:curl_version).and_return(Version.new("8.7.1"))
 | 
			
		||||
 | 
			
		||||
      allow(strategy).to receive(:system_command)
 | 
			
		||||
        .with(
 | 
			
		||||
          /curl/,
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,8 @@ RSpec.describe CurlPostDownloadStrategy do
 | 
			
		||||
 | 
			
		||||
  describe "#fetch" do
 | 
			
		||||
    before do
 | 
			
		||||
      allow(strategy).to receive(:curl_version).and_return(Version.new("8.6.0"))
 | 
			
		||||
 | 
			
		||||
      allow(strategy).to receive(:system_command)
 | 
			
		||||
        .with(
 | 
			
		||||
          /curl/,
 | 
			
		||||
 | 
			
		||||
@ -234,7 +234,11 @@ module Utils
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def curl_headers(*args, wanted_headers: [], **options)
 | 
			
		||||
      [[], ["--request", "GET"]].each do |request_args|
 | 
			
		||||
      get_retry_args = ["--request", "GET"]
 | 
			
		||||
      # This is a workaround for https://github.com/Homebrew/brew/issues/18213
 | 
			
		||||
      get_retry_args << "--http1.1" if curl_version >= Version.new("8.7") && curl_version < Version.new("8.10")
 | 
			
		||||
 | 
			
		||||
      [[], get_retry_args].each do |request_args|
 | 
			
		||||
        result = curl_output(
 | 
			
		||||
          "--fail", "--location", "--silent", "--head", *request_args, *args,
 | 
			
		||||
          **options
 | 
			
		||||
@ -494,9 +498,14 @@ module Utils
 | 
			
		||||
      T.must(file).unlink
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def curl_version
 | 
			
		||||
      @curl_version ||= {}
 | 
			
		||||
      @curl_version[curl_path] ||= Version.new(curl_output("-V").stdout[/curl (\d+(\.\d+)+)/, 1])
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def curl_supports_fail_with_body?
 | 
			
		||||
      @curl_supports_fail_with_body ||= Hash.new do |h, key|
 | 
			
		||||
        h[key] = Version.new(curl_output("-V").stdout[/curl (\d+(\.\d+)+)/, 1]) >= Version.new("7.76.0")
 | 
			
		||||
        h[key] = curl_version >= Version.new("7.76.0")
 | 
			
		||||
      end
 | 
			
		||||
      @curl_supports_fail_with_body[curl_path]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user