This repository was archived by the owner on Dec 18, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
src/Microsoft.Framework.PackageManager Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ public int Main(string[] args)
56
56
CommandOptionType . MultipleValue ) ;
57
57
var optFallbackSource = c . Option ( "-f|--fallbacksource <FEED>" ,
58
58
"A list of packages sources to use as a fallback" , CommandOptionType . MultipleValue ) ;
59
+ var optProxy = c . Option ( "-p|--proxy <ADDRESS>" , "The HTTP proxy to use when retrieving packages" ,
60
+ CommandOptionType . SingleValue ) ;
59
61
c . HelpOption ( "-?|-h|--help" ) ;
60
62
61
63
c . OnExecute ( ( ) =>
@@ -73,6 +75,16 @@ public int Main(string[] args)
73
75
{
74
76
command . FallbackSources = optFallbackSource . Values ;
75
77
}
78
+ if ( optProxy . HasValue ( ) )
79
+ {
80
+ #if NET45
81
+ Environment . SetEnvironmentVariable ( "http_proxy" , optProxy . Value ( ) ,
82
+ EnvironmentVariableTarget . Process ) ;
83
+ #else
84
+ throw new NotImplementedException (
85
+ "TODO: \" kpm --proxy\" is not supported on current target framework" ) ;
86
+ #endif
87
+ }
76
88
var success = command . ExecuteCommand ( ) ;
77
89
78
90
return success ? 0 : 1 ;
Original file line number Diff line number Diff line change 9
9
using System . IO . Compression ;
10
10
using System . IO . Packaging ;
11
11
using System . Linq ;
12
+ using System . Net ;
12
13
using System . Net . Http ;
13
14
using System . Net . Http . Headers ;
14
15
using System . Text ;
@@ -44,7 +45,37 @@ public PackageFeed(
44
45
_userName = userName ;
45
46
_password = password ;
46
47
_report = report ;
47
- _httpClient = new HttpClient ( ) ;
48
+
49
+ var proxy = Environment . GetEnvironmentVariable ( "http_proxy" ) ;
50
+ if ( string . IsNullOrEmpty ( proxy ) )
51
+ {
52
+ _httpClient = new HttpClient ( ) ;
53
+ }
54
+ else
55
+ {
56
+ // To use an authenticated proxy, the proxy address should be in the form of
57
+ // "http://user:[email protected] :8888"
58
+ var proxyUriBuilder = new UriBuilder ( proxy ) ;
59
+ var webProxy = new WebProxy ( proxy ) ;
60
+ if ( string . IsNullOrEmpty ( proxyUriBuilder . UserName ) )
61
+ {
62
+ // If no credentials were specified we use default credentials
63
+ webProxy . Credentials = CredentialCache . DefaultCredentials ;
64
+ }
65
+ else
66
+ {
67
+ ICredentials credentials = new NetworkCredential ( proxyUriBuilder . UserName ,
68
+ proxyUriBuilder . Password ) ;
69
+ webProxy . Credentials = credentials ;
70
+ }
71
+
72
+ var handler = new HttpClientHandler
73
+ {
74
+ Proxy = webProxy ,
75
+ UseProxy = true
76
+ } ;
77
+ _httpClient = new HttpClient ( handler ) ;
78
+ }
48
79
}
49
80
50
81
Dictionary < string , Task < IEnumerable < PackageInfo > > > _cache = new Dictionary < string , Task < IEnumerable < PackageInfo > > > ( ) ;
You can’t perform that action at this time.
0 commit comments