/
HttpMessageHandler.cs
43 lines (36 loc) · 1.51 KB
/
HttpMessageHandler.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace System.Net.Http
{
public abstract class HttpMessageHandler : IDisposable
{
protected HttpMessageHandler()
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this);
}
// We cannot add abstract member to a public class in order to not to break already established contract of this class.
// So we add virtual method, override it everywhere internally and provide proper implementation.
// Unfortunately we cannot force everyone to implement so in such case we throw NSE.
protected internal virtual HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
{
throw new NotSupportedException(SR.Format(SR.net_http_missing_sync_implementation, GetType(), nameof(HttpMessageHandler), nameof(Send)));
}
protected internal abstract Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken);
#region IDisposable Members
protected virtual void Dispose(bool disposing)
{
// Nothing to do in base class.
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}