-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathBaseRequestPayloadExtractor.cs
51 lines (46 loc) · 1.51 KB
/
BaseRequestPayloadExtractor.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
44
45
46
47
48
49
50
51
namespace Sentry.Extensibility
{
/// <summary>
/// Base type for payload extraction.
/// </summary>
public abstract class BaseRequestPayloadExtractor : IRequestPayloadExtractor
{
/// <summary>
/// Extract the payload of the <see cref="IHttpRequest"/>.
/// </summary>
public object? ExtractPayload(IHttpRequest request)
{
// Not to throw on code that ignores nullability warnings.
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (request is null)
{
return null;
}
if (request.Body == null
|| !request.Body.CanSeek
|| !request.Body.CanRead
|| !IsSupported(request))
{
return null;
}
var originalPosition = request.Body.Position;
try
{
request.Body.Position = 0;
return DoExtractPayLoad(request);
}
finally
{
request.Body.Position = originalPosition;
}
}
/// <summary>
/// Whether this implementation supports the <see cref="IHttpRequest"/>.
/// </summary>
protected abstract bool IsSupported(IHttpRequest request);
/// <summary>
/// The extraction that gets called in case <see cref="IsSupported"/> is true.
/// </summary>
protected abstract object? DoExtractPayLoad(IHttpRequest request);
}
}