@@ -35,6 +35,14 @@ public partial class RestClient : IDisposable {
35
35
/// </summary>
36
36
public string [ ] AcceptedContentTypes { get ; set ; } = null ! ;
37
37
38
+ /// <summary>
39
+ /// Function to calculate the response status. By default, the status will be Completed if it was successful, or NotFound.
40
+ /// </summary>
41
+ public CalculateResponseStatus CalculateResponseStatus { get ; set ; } = httpResponse
42
+ => httpResponse . IsSuccessStatusCode || httpResponse . StatusCode == HttpStatusCode . NotFound
43
+ ? ResponseStatus . Completed
44
+ : ResponseStatus . Error ;
45
+
38
46
HttpClient HttpClient { get ; }
39
47
40
48
internal RestClientOptions Options { get ; }
@@ -103,8 +111,7 @@ public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
103
111
public RestClient ( HttpMessageHandler handler , bool disposeHandler = true ) : this ( new HttpClient ( handler , disposeHandler ) , null , true ) { }
104
112
105
113
void ConfigureHttpClient ( HttpClient httpClient ) {
106
- if ( Options . Timeout > 0 )
107
- httpClient . Timeout = TimeSpan . FromMilliseconds ( Options . Timeout ) ;
114
+ if ( Options . Timeout > 0 ) httpClient . Timeout = TimeSpan . FromMilliseconds ( Options . Timeout ) ;
108
115
httpClient . DefaultRequestHeaders . UserAgent . ParseAdd ( Options . UserAgent ) ;
109
116
}
110
117
@@ -126,8 +133,7 @@ void ConfigureHttpMessageHandler(HttpClientHandler handler) {
126
133
handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
127
134
}
128
135
129
- if ( Options . MaxRedirects . HasValue )
130
- handler . MaxAutomaticRedirections = Options . MaxRedirects . Value ;
136
+ if ( Options . MaxRedirects . HasValue ) handler . MaxAutomaticRedirections = Options . MaxRedirects . Value ;
131
137
}
132
138
133
139
internal Func < string , string > Encode { get ; set ; } = s => s . UrlEncode ( ) ;
@@ -153,7 +159,7 @@ public RestClient AddDefaultParameter(Parameter parameter) {
153
159
) ;
154
160
155
161
if ( ! Options . AllowMultipleDefaultParametersWithSameName &&
156
- ! MultiParameterTypes . Contains ( parameter . Type ) &&
162
+ ! MultiParameterTypes . Contains ( parameter . Type ) &&
157
163
DefaultParameters . Any ( x => x . Name == parameter . Name ) ) {
158
164
throw new ArgumentException ( "A default parameters with the same name has already been added" , nameof ( parameter ) ) ;
159
165
}
@@ -212,4 +218,4 @@ public void Dispose() {
212
218
Dispose ( true ) ;
213
219
GC . SuppressFinalize ( this ) ;
214
220
}
215
- }
221
+ }
0 commit comments