8000 Make managed http opt-in on non-Linux OSes · dotdevelop/libgit2sharp@9ee00e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ee00e4

Browse files
committed
Make managed http opt-in on non-Linux OSes
1 parent d2db2ac commit 9ee00e4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private static void InitializeNativeLibrary()
206206

207207
#if !NET46
208208
// Configure the .NET HTTP(S) mechanism on the first initialization of the library in the current process.
209-
if (initCounter == 1)
209+
if (initCounter == 1 && GlobalSettings.ManagedHttpSmartSubtransportEnabled)
210210
{
211211
httpSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("http");
212212
httpsSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("https");

LibGit2Sharp/GlobalSettings.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public static class GlobalSettings
2222
private static bool nativeLibraryPathLocked;
2323
private static string nativeLibraryDefaultPath;
2424

25+
#if !NET46
26+
private static bool useManagedHttpSmartSubtransport;
27+
#endif
28+
2529
internal class SmartSubtransportData
2630
{
2731
internal bool isCustom;
@@ -79,13 +83,11 @@ private static string GetExecutingAssemblyDirectory()
7983
/// Returns information related to the current LibGit2Sharp
8084
/// library.
8185
/// </summary>
82-
public static Version Version
83-
{
84-
get
85-
{
86-
return version.Value;
87-
}
88-
}
86+
public static Version Version => version.Value;
87+
88+
#if !NET46
89+
internal static bool ManagedHttpSmartSubtransportEnabled => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || useManagedHttpSmartSubtransport;
90+
#endif
8991

9092
private static SmartSubtransportData GetOrCreateSmartSubtransportData(string scheme)
9193
{
@@ -541,5 +543,15 @@ public static string GetUserAgent()
541543
{
542544
return Proxy.git_libgit2_opts_get_user_agent();
543545
}
546+
547+
#if !NET46
548+
/// <summary>
549+
/// Enables the managed http implementation. This is enabled autmatically on Linux, so this method is only needed when running on Windows or macOS.
550+
/// </summary>
551+
public static void UseManagedHttpSmartSubtransport()
552+
{
553+
useManagedHttpSmartSubtransport = true;
554+
}
555+
#endif
544556
}
545557
}

0 commit comments

Comments
 (0)
0