Skip to content

Commit

Permalink
Make managed http opt-in on non-Linux OSes
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Apr 7, 2020
1 parent d2db2ac commit 9ee00e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static void InitializeNativeLibrary()

#if !NET46
// Configure the .NET HTTP(S) mechanism on the first initialization of the library in the current process.
if (initCounter == 1)
if (initCounter == 1 && GlobalSettings.ManagedHttpSmartSubtransportEnabled)
{
httpSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("http");
httpsSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("https");
Expand Down
26 changes: 19 additions & 7 deletions LibGit2Sharp/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static class GlobalSettings
private static bool nativeLibraryPathLocked;
private static string nativeLibraryDefaultPath;

#if !NET46
private static bool useManagedHttpSmartSubtransport;
#endif

internal class SmartSubtransportData
{
internal bool isCustom;
Expand Down Expand Up @@ -79,13 +83,11 @@ private static string GetExecutingAssemblyDirectory()
/// Returns information related to the current LibGit2Sharp
/// library.
/// </summary>
public static Version Version
{
get
{
return version.Value;
}
}
public static Version Version => version.Value;

#if !NET46
internal static bool ManagedHttpSmartSubtransportEnabled => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || useManagedHttpSmartSubtransport;
#endif

private static SmartSubtransportData GetOrCreateSmartSubtransportData(string scheme)
{
Expand Down Expand Up @@ -541,5 +543,15 @@ public static string GetUserAgent()
{
return Proxy.git_libgit2_opts_get_user_agent();
}

#if !NET46
/// <summary>
/// Enables the managed http implementation. This is enabled autmatically on Linux, so this method is only needed when running on Windows or macOS.
/// </summary>
public static void UseManagedHttpSmartSubtransport()
{
useManagedHttpSmartSubtransport = true;
}
#endif
}
}

0 comments on commit 9ee00e4

Please sign in to comment.