@@ -35,6 +35,14 @@ public partial class RestClient : IDisposable {
3535 /// </summary>
3636 public string [ ] AcceptedContentTypes { get ; set ; } = null ! ;
3737
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+
3846 HttpClient HttpClient { get ; }
3947
4048 internal RestClientOptions Options { get ; }
@@ -103,8 +111,7 @@ public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
103111 public RestClient ( HttpMessageHandler handler , bool disposeHandler = true ) : this ( new HttpClient ( handler , disposeHandler ) , null , true ) { }
104112
105113 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 ) ;
108115 httpClient . DefaultRequestHeaders . UserAgent . ParseAdd ( Options . UserAgent ) ;
109116 }
110117
@@ -126,8 +133,7 @@ void ConfigureHttpMessageHandler(HttpClientHandler handler) {
126133 handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
127134 }
128135
129- if ( Options . MaxRedirects . HasValue )
130- handler . MaxAutomaticRedirections = Options . MaxRedirects . Value ;
136+ if ( Options . MaxRedirects . HasValue ) handler . MaxAutomaticRedirections = Options . MaxRedirects . Value ;
131137 }
132138
133139 internal Func < string , string > Encode { get ; set ; } = s => s . UrlEncode ( ) ;
@@ -153,7 +159,7 @@ public RestClient AddDefaultParameter(Parameter parameter) {
153159 ) ;
154160
155161 if ( ! Options . AllowMultipleDefaultParametersWithSameName &&
156- ! MultiParameterTypes . Contains ( parameter . Type ) &&
162+ ! MultiParameterTypes . Contains ( parameter . Type ) &&
157163 DefaultParameters . Any ( x => x . Name == parameter . Name ) ) {
158164 throw new ArgumentException ( "A default parameters with the same name has already been added" , nameof ( parameter ) ) ;
159165 }
@@ -212,4 +218,4 @@ public void Dispose() {
212218 Dispose ( true ) ;
213219 GC . SuppressFinalize ( this ) ;
214220 }
215- }
221+ }
0 commit comments