Skip to content

Commit 59c9ba1

Browse files
authored
Improve Mono support: Use correct HttpRequestMessage headers field name under Mono (#26)
1 parent 5cba41e commit 59c9ba1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

StandardSocketsHttpHandler/Net/Http/Extensions/HttpRequestMessageExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ internal static class HttpRequestMessageExtensions
88
{
99
public static bool HasHeaders(this HttpRequestMessage request)
1010
{
11-
// Note: The field name is _headers in .NET core
11+
// Note: The field name is _headers in .NET core, and headers in .NET Mono / .NET Framework
1212
bool isDotNetFramework = RuntimeUtils.IsDotNetFramework();
13-
string headersFieldName = isDotNetFramework ? "headers" : "_headers";
13+
bool isMono = RuntimeUtils.IsMono();
14+
string headersFieldName = isDotNetFramework || isMono ? "headers" : "_headers";
1415
FieldInfo headersField = typeof(HttpRequestMessage).GetField(headersFieldName, BindingFlags.Instance | BindingFlags.NonPublic);
1516
if (headersField == null && isDotNetFramework)
1617
{

StandardSocketsHttpHandler/Utils/RuntimeUtils.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ public static bool IsDotNetNative()
1818
string frameworkDescription = RuntimeInformation.FrameworkDescription;
1919
return frameworkDescription.StartsWith(DotnetFrameworkDescription);
2020
}
21+
22+
public static bool IsMono()
23+
{
24+
const string MonoDescription = "Mono";
25+
string frameworkDescription = RuntimeInformation.FrameworkDescription;
26+
return frameworkDescription.StartsWith(MonoDescription);
27+
}
2128
}
2229
}

0 commit comments

Comments
 (0)