Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ac4bf3e

Browse files
committed
Initial xplat work for HttpClient
1 parent 196c836 commit ac4bf3e

File tree

9 files changed

+1271
-453
lines changed

9 files changed

+1271
-453
lines changed

src/Common/src/Interop/Unix/Interop.Libraries.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ internal static partial class Interop
55
{
66
private static partial class Libraries
77
{
8+
internal const string CryptoInterop = "System.Security.Cryptography.Native";
9+
internal const string IOInterop = "System.IO.Native";
810
internal const string Libc = "libc"; // C library
911
internal const string LibCoreClr= "libcoreclr"; // CoreCLR runtime
1012
internal const string LibCrypto = "libcrypto"; // OpenSSL crypto library
13+
internal const string LibCurl = "libcurl"; // Curl HTTP client library
1114
internal const string Zlib = "libz"; // zlib compression library
12-
internal const string IOInterop = "System.IO.Native";
13-
internal const string CryptoInterop = "System.Security.Cryptography.Native";
1415
}
1516
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class libcurl
10+
{
11+
internal sealed class SafeCurlHandle : SafeHandle
12+
{
13+
public SafeCurlHandle() : base(IntPtr.Zero, true)
14+
{
15+
}
16+
17+
public override bool IsInvalid
18+
{
19+
get { return this.handle == IntPtr.Zero; }
20+
}
21+
22+
public static void DisposeAndClearHandle(ref SafeCurlHandle curlHandle)
23+
{
24+
if (curlHandle != null)
25+
{
26+
curlHandle.Dispose();
27+
curlHandle = null;
28+
}
29+
}
30+
31+
protected override bool ReleaseHandle()
32+
{
33+
Interop.libcurl.curl_easy_cleanup(this.handle);
34+
return true;
35+
}
36+
}
37+
}
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class libcurl
10+
{
11+
[DllImport(Interop.Libraries.LibCurl)]
12+
public static extern SafeCurlHandle curl_easy_init();
13+
14+
[DllImport(Interop.Libraries.LibCurl)]
15+
public static extern void curl_easy_cleanup(
16+
IntPtr handle);
17+
18+
[DllImport(Interop.Libraries.LibCurl, CharSet = CharSet.Ansi)]
19+
public static extern int curl_easy_setopt(
20+
SafeCurlHandle curl,
21+
int option,
22+
string value);
23+
24+
[DllImport(Interop.Libraries.LibCurl)]
25+
public static extern int curl_easy_setopt(
26+
SafeCurlHandle curl,
27+
int option,
28+
long value);
29+
30+
[DllImport(Interop.Libraries.LibCurl)]
31+
public static extern int curl_easy_perform(
32+
SafeCurlHandle curl);
33+
34+
[DllImport(Interop.Libraries.LibCurl)]
35+
public static extern IntPtr curl_easy_strerror(
36+
int code);
37+
38+
[DllImport(Interop.Libraries.LibCurl)]
39+
public static extern int curl_easy_getinfo(
40+
SafeCurlHandle curl,
41+
int info,
42+
ref long value); // Using a ref because it won't be populated on error
43+
}
44+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
internal static partial class Interop
5+
{
6+
internal static partial class libcurl
7+
{
8+
// Class for constants defined for the enum CURLoption in curl.h
9+
internal static partial class CURLoption
10+
{
11+
// Curl options are of the format <type base> + <n>
12+
private const int CurlOptionLongBase = 0;
13+
private const int CurlOptionObjectPointBase = 10000;
14+
15+
internal const int CURLOPT_FOLLOWLOCATION = CurlOptionLongBase + 52;
16+
internal const int CURLOPT_URL = CurlOptionObjectPointBase + 2;
17+
}
18+
19+
// Class for constants defined for the enum CURLINFO in curl.h
20+
internal static partial class CURLINFO
21+
{
22+
// Curl info are of the format <type base> + <n>
23+
private const int CurlInfoLongBase = 0x200000;
24+
internal const int CURLINFO_RESPONSE_CODE = CurlInfoLongBase + 2;
25+
}
26+
27+
// Class for constants defined for the enum CURLcode in curl.h
28+
internal static partial class CURLcode
29+
{
30+
internal const int CURLE_OK = 0;
31+
}
32+
}
33+
}

src/System.Net.Http/src/System.Net.Http.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,20 @@
133133
</ItemGroup>
134134

135135
<ItemGroup Condition=" '$(TargetsUnix)' == 'true' ">
136-
<Compile Include="System\Net\Http\HttpClientHandler.Unix.cs" />
136+
<Compile Include="System\Net\Http\Unix\CurlHandler.cs" />
137+
<Compile Include="System\Net\Http\Unix\HttpClientHandler.Unix.cs" />
138+
<Compile Include="$(CommonPath)\Interop\Unix\Interop.Libraries.cs">
139+
<Link>Common\Interop\Unix\Interop.Libraries.cs</Link>
140+
</Compile>
141+
<Compile Include="$(CommonPath)\Interop\Unix\libcurl\Interop.libcurl.cs">
142+
<Link>Common\Interop\Unix\libcurl\Interop.libcurl.cs</Link>
143+
</Compile>
144+
<Compile Include="$(CommonPath)\Interop\Unix\libcurl\Interop.libcurl_types.cs">
145+
<Link>Common\Interop\Unix\libcurl\Interop.libcurl_types.cs</Link>
146+
</Compile>
147+
<Compile Include="$(CommonPath)\Interop\Unix\libcurl\Interop.SafeCurlHandle.cs">
148+
<Link>Common\Interop\Unix\libcurl\Interop.SafeCurlHandle.cs</Link>
149+
</Compile>
137150
<Compile Include="$(CommonPath)\System\NotImplemented.cs">
138151
<Link>Common\System\NotImplemented.cs</Link>
139152
</Compile>

0 commit comments

Comments
 (0)