-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCurlHttpWebResponse.cs
More file actions
58 lines (36 loc) · 1.49 KB
/
CurlHttpWebResponse.cs
File metadata and controls
58 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Gsemac.Net.Http;
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Gsemac.Net.Curl {
[ResponseStreamAlreadyDecompressed]
internal sealed class CurlHttpWebResponse :
CurlHttpWebResponseBase {
// Public members
internal CurlHttpWebResponse(IHttpWebRequest originatingRequest, Stream responseStream, Task curlTask, CancellationTokenSource cancellationTokenSource) :
base(originatingRequest, responseStream, () => curlTask.Exception?.InnerExceptions.First()) {
if (originatingRequest is null)
throw new ArgumentNullException(nameof(originatingRequest));
if (responseStream is null)
throw new ArgumentNullException(nameof(responseStream));
if (cancellationTokenSource is null)
throw new ArgumentNullException(nameof(cancellationTokenSource));
this.cancellationTokenSource = cancellationTokenSource;
ReadHttpHeadersFromStream();
}
public override void Close() {
if (!isClosed) {
// Cancel the Curl reading thread.
cancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
isClosed = true;
}
base.Close();
}
// Private members
private bool isClosed;
private readonly CancellationTokenSource cancellationTokenSource;
}
}