flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.17k stars 27.25k forks source link

Flutter should respect proxy settings on Windows during Dart SDK download #10903

Open felix-hubo opened 7 years ago

felix-hubo commented 7 years ago

I met errors when running flutter doctor. It's related with proxy settings.

Flutter Doctor

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\CNFEHU1>flutter doctor
Checking Dart SDK version...
Downloading Dart SDK 1.24.0-dev.6.7...
Start-BitsTransfer : HTTP status 407: Proxy authentication is required.
At C:\Users\CNFEHU1\Documents\GitHub\flutter\bin\internal\update_dart_sdk.ps1:4
4 char:19
+ Start-BitsTransfer <<<<  -Source $dartSdkUrl -Destination $dartSdkZip
    + CategoryInfo          : InvalidOperation: (:) [Start-BitsTransfer], Exce
   ption
    + FullyQualifiedErrorId : StartBitsTransferCOMException,Microsoft.Backgrou
   ndIntelligentTransfer.Management.NewBitsTransferCommand

Error: Unable to update Dart SDK. Retrying...
eseidelGoogle commented 7 years ago

@goderbauer might know. Looks like it's not using your network proxy correctly?

goderbauer commented 7 years ago

If your proxy requires manual configuration, we currently offer no way to do that for the initial download of the Dart SDK. We should probably do what pub does and respect the http_proxy env variable, if present (see https://www.dartlang.org/tools/pub/troubleshoot#pub-get-fails-from-behind-a-corporate-firewall). Linux's curl util automatically uses that env. On Windows, we've to teach BitsTransfer how to use it it seems...

If you are feeling adventures: This is the line where we use Windows's BitsTransfer to download the SDK: https://github.com/flutter/flutter/blob/master/bin/internal/update_dart_sdk.ps1#L44. And this is the documentation describing the proxy settings for BitsTransfer: https://technet.microsoft.com/en-us/library/dd819420.aspx. If you attempt this, let me know what settings were required to make it work.

wangyun commented 6 years ago

I add -ProxyUsage Override -ProxyList 192.168.0.118:1080 to: Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip and it works.

jAwAno commented 6 years ago

We also need to get over a proxy and it has BASIC authentication. and we alredy have "http_proxy" variable at envitronment as this format

http://username:pass@proxyHost:port

so I added this codes for resolve problem at update_dart_sdk.ps1 and it works fine

If($httpProxy = ([System.Uri] $env:http_proxy)){
    $proxyUserInfo = $httpProxy.UserInfo.Split(":")
    $proxyPass = ConvertTo-SecureString $proxyUserInfo[1] -AsPlainText -Force
    $proxyCredential = New-Object System.Management.Automation.PSCredential ($proxyUserInfo[0], $proxyPass)

    Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip -ProxyUsage Override -ProxyList ($httpProxy.Host + ":" + $httpProxy.Port) -ProxyCredential $proxyCredential -ProxyAuthentication Basic    
}Else{
    Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip
}
goderbauer commented 6 years ago

@jAwAno would you be willing to send us a pull request with that change?

igitur commented 6 years ago

@goderbauer Hang on. That change might break a lot of other users' setup. Start-BitsTransfer is supposed to honor the Windows system proxy settings, right?

goderbauer commented 6 years ago

This would only change things for users, that have $env:http_proxy set explicitly, no?

jAwAno commented 6 years ago

@goderbauer I sent a pull request . and Yes this change will only affect for user who defined http_proxy at environment variables.

igitur commented 6 years ago

@goderbauer True, but I'm one of those users who has http_proxy set, for very specific purposes. And a lot of times, clients would fail to use that because our proxy requires NTLM authentication. I still believe that since Start-BitsTransfer is supposed to honor the Windows system proxy settings, we should look into why that is not happening for the user, instead of building in workarounds that might cause more problems.

One guess is that Start-BitsTransfer could be failing because of missing or expired credentials. In that case the -UseStoredCredential Proxy switch might help. (@jAwAno , please rather that instead of the http_proxy workaround).

Let's not be hasty about this. Understand the cause before trying to fix it.

igitur commented 6 years ago

@jAwAno Please confirm whether your Windows proxy settings are populated correctly.

jAwAno commented 6 years ago

@igitur Ok I'll check my setting again , and actually you're right fixing authentication method to BASIC is bad way . hm I'll find some other way

codeitbhanu commented 6 years ago

This Worked For Me:

Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip -ProxyAuthentication Basic -ProxyUsage Override -ProxyCredential YOUR_USERNAME -ProxyList IP_ADDRESS:PORT_NO
sam17896 commented 4 years ago

This is still an issue in December 2019.

plato79 commented 3 years ago

We also need to get over a proxy and it has BASIC authentication. and we alredy have "http_proxy" variable at envitronment as this format

http://username:pass@proxyHost:port

so I added this codes for resolve problem at update_dart_sdk.ps1 and it works fine

If($httpProxy = ([System.Uri] $env:http_proxy)){
    $proxyUserInfo = $httpProxy.UserInfo.Split(":")
    $proxyPass = ConvertTo-SecureString $proxyUserInfo[1] -AsPlainText -Force
    $proxyCredential = New-Object System.Management.Automation.PSCredential ($proxyUserInfo[0], $proxyPass)

    Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip -ProxyUsage Override -ProxyList ($httpProxy.Host + ":" + $httpProxy.Port) -ProxyCredential $proxyCredential -ProxyAuthentication Basic    
}Else{
    Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip
}

While the code above is good, as @jAwAno said, authentication could be a problem. I'm using CNTLM to forward NTLM proxy to HTTP proxy and use it for git. Although I'm not using any authentication so lines with authentication actually is a bit problem for me. So I think we need to check if there's authentication ( user/password ) in proxy line or not. If it's not available we need to remove -ProxyCredential and -ProxyAuthentication parameters.