-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathIRequestBuilder.cs
More file actions
110 lines (96 loc) · 3.94 KB
/
IRequestBuilder.cs
File metadata and controls
110 lines (96 loc) · 3.94 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace StackExchange.Utils
{
/// <summary>
/// A request construct for building request options before issuing.
/// </summary>
public interface IRequestBuilder
{
/// <summary>
/// The settings to use for this request. If null, <see cref="Http.DefaultSettings"/> should be used.
/// </summary>
HttpSettings Settings { get; }
/// <summary>
/// The request message being built.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
HttpRequestMessage Message { get; }
/// <summary>
/// Whether to log errors.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
bool LogErrors { get; set; }
/// <summary>
/// Whether to log error response body on a given http status code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
IEnumerable<HttpStatusCode> LogErrorResponseBodyStatuses { get; set; }
/// <summary>
/// Which <see cref="HttpStatusCode"/>s to ignore as errors on responses.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
IEnumerable<HttpStatusCode> IgnoredResponseStatuses { get; set; }
/// <summary>
/// The timeout to use on this request.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
TimeSpan Timeout { get; set; }
/// <summary>
/// Indicate if the response content should be buffered (e.g. for access later, vs. only streamed when false).
/// Sets the HttpCompletionOption to use on this request accordingly.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
bool BufferResponse { get; set; }
/// <summary>
/// The Proxy to use when making requests
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
IWebProxy Proxy { get; set; }
/// <summary>
/// The <see cref="IHttpClientPool"/> to get a client from.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
IHttpClientPool ClientPool { get; set; }
/// <summary>
/// An before-logging event to call in case on an error.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
event EventHandler<HttpExceptionArgs> BeforeExceptionLog;
/// <summary>
/// Called before an exception is logged.
/// </summary>
/// <param name="args">The arguments wrapper for the exception thrown.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
void OnBeforeExceptionLog(HttpExceptionArgs args);
/// <summary>
/// Adds a handler to this request builder.
/// </summary>
/// <typeparam name="T">The payload type for this request.</typeparam>
/// <param name="handler">The handler to add to this builder, used for extensions.</param>
/// <returns>A wrapping <see cref="IRequestBuilder{T}"/> with the handler.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
IRequestBuilder<T> WithHandler<T>(Func<HttpResponseMessage, Task<T>> handler);
}
/// <summary>
/// A typed request construct for building request options before issuing.
/// </summary>
/// <typeparam name="T">The type this request will return.</typeparam>
public interface IRequestBuilder<T>
{
/// <summary>
/// The wrapped <see cref="IRequestBuilder"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
IRequestBuilder Inner { get; }
/// <summary>
/// The response handler for this request.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
Func<HttpResponseMessage, Task<T>> Handler { get; }
}
}