Skip to content

Commit

Permalink
(NuGet#9) Allow explicit proxy override
Browse files Browse the repository at this point in the history
Allow passing a specific proxy into the proxy cache that is used no
matter what.

Based on these commits:
chocolatey/nuget-chocolatey@4b206ed
chocolatey/nuget-chocolatey@26559a4

Co-Authored-By: Rob Reynolds <[email protected]>
Co-Authored-By: Jakub Cisło <[email protected]>
  • Loading branch information
3 people authored and gep13 committed Nov 21, 2022
1 parent 3c891b1 commit 5e4e81b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/NuGet.Core/NuGet.Configuration/Proxy/ChocolateyProxyCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////

using System.Net;

namespace NuGet.Configuration
{
public partial class ProxyCache : IProxyCache, IProxyCredentialCache
{
private IWebProxy _overrideProxy;
private bool _isProxyOverridden = false;

public void Override(IWebProxy proxy)
{
_overrideProxy = proxy;
_isProxyOverridden = true;
}

public void ClearOverriding()
{
_overrideProxy = null;
_isProxyOverridden = false;
}
}
}
24 changes: 23 additions & 1 deletion src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

namespace NuGet.Configuration
{
public class ProxyCache : IProxyCache, IProxyCredentialCache
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

public partial class ProxyCache : IProxyCache, IProxyCredentialCache

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

{
#if !IS_CORECLR
/// <summary>
Expand Down Expand Up @@ -48,6 +57,19 @@ public ProxyCache(ISettings settings, IEnvironmentVariableReader environment)

public IWebProxy GetProxy(Uri sourceUri)
{
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

if (_isProxyOverridden)
{
return _overrideProxy;
}

//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

// Check if the user has configured proxy details in settings or in the environment.
var configuredProxy = GetUserConfiguredProxy();
if (configuredProxy != null)
Expand Down
2 changes: 2 additions & 0 deletions src/NuGet.Core/NuGet.Configuration/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ NuGet.Configuration.NuGetConfigurationException.NuGetConfigurationException(Syst
NuGet.Configuration.PackageSourceMappingProvider
NuGet.Configuration.PackageSourceMappingProvider.PackageSourceMappingProvider(NuGet.Configuration.ISettings settings) -> void
NuGet.Configuration.PackageSourceMappingProvider.SavePackageSourceMappings(System.Collections.Generic.IReadOnlyList<NuGet.Configuration.PackageSourceMappingSourceItem> packageSourceMappingsSourceItems) -> void
NuGet.Configuration.ProxyCache.ClearOverriding() -> void
NuGet.Configuration.ProxyCache.Override(System.Net.IWebProxy proxy) -> void

0 comments on commit 5e4e81b

Please sign in to comment.