2525using System . Text . RegularExpressions ;
2626using RestSharp . Extensions ;
2727
28+ #pragma warning disable 618
29+
2830namespace RestSharp
2931{
3032 /// <summary>
@@ -36,6 +38,7 @@ public partial class Http : IHttp
3638
3739 public string FormBoundary { get ; } = "---------" + Guid . NewGuid ( ) . ToString ( ) . ToUpper ( ) ;
3840
41+ // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
3942 static readonly Regex AddRangeRegex = new Regex ( "(\\ w+)=(\\ d+)-(\\ d+)$" ) ;
4043
4144 readonly IDictionary < string , Action < HttpWebRequest , string > > _restrictedHeaderActions ;
@@ -143,10 +146,10 @@ static void AddRange(HttpWebRequest r, string range)
143146 public int ReadWriteTimeout { get ; set ; }
144147
145148 /// <inheritdoc />
146- public ICredentials Credentials { get ; set ; }
149+ public ICredentials ? Credentials { get ; set ; }
147150
148151 /// <inheritdoc />
149- public CookieContainer CookieContainer { get ; set ; }
152+ public CookieContainer ? CookieContainer { get ; set ; }
150153
151154 /// <inheritdoc />
152155 public Action < Stream , IHttpResponse > AdvancedResponseWriter { get ; set ; }
@@ -164,7 +167,7 @@ static void AddRange(HttpWebRequest r, string range)
164167 public bool Pipelined { get ; set ; }
165168
166169 /// <inheritdoc />
167- public X509CertificateCollection ClientCertificates { get ; set ; }
170+ public X509CertificateCollection ? ClientCertificates { get ; set ; }
168171
169172 /// <inheritdoc />
170173 public int ? MaxRedirects { get ; set ; }
@@ -200,7 +203,7 @@ static void AddRange(HttpWebRequest r, string range)
200203 public Uri Url { get ; set ; }
201204
202205 /// <inheritdoc />
203- public string Host { get ; set ; }
206+ public string ? Host { get ; set ; }
204207
205208 /// <inheritdoc />
206209 public IList < DecompressionMethods > AllowedDecompressionMethods { get ; set ; }
@@ -212,25 +215,25 @@ static void AddRange(HttpWebRequest r, string range)
212215 public bool UnsafeAuthenticatedConnectionSharing { get ; set ; }
213216
214217 /// <inheritdoc />
215- public IWebProxy Proxy { get ; set ; }
218+ public IWebProxy ? Proxy { get ; set ; }
216219
217220 /// <inheritdoc />
218- public RequestCachePolicy CachePolicy { get ; set ; }
221+ public RequestCachePolicy ? CachePolicy { get ; set ; }
219222
220223 /// <inheritdoc />
221224 /// <summary>
222225 /// Callback function for handling the validation of remote certificates.
223226 /// </summary>
224- public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get ; set ; }
227+ public RemoteCertificateValidationCallback ? RemoteCertificateValidationCallback { get ; set ; }
225228
226229 /// <inheritdoc />
227- public Action < HttpWebRequest > WebRequestConfigurator { get ; set ; }
230+ public Action < HttpWebRequest > ? WebRequestConfigurator { get ; set ; }
228231
229232 [ Obsolete ]
230233 public static IHttp Create ( ) => new Http ( ) ;
231234
232235 [ Obsolete ( "Overriding this method won't be possible in future version" ) ]
233- protected virtual HttpWebRequest CreateWebRequest ( Uri url ) => null ;
236+ protected virtual HttpWebRequest ? CreateWebRequest ( Uri url ) => null ;
234237
235238 static HttpWebRequest CreateRequest ( Uri uri ) => ( HttpWebRequest ) WebRequest . Create ( uri ) ;
236239
@@ -245,7 +248,7 @@ string GetMultipartFormData(HttpParameter param)
245248 ? "--{0}{3}Content-Type: {4}{3}Content-Disposition: form-data; name=\" {1}\" {3}{3}{2}{3}"
246249 : "--{0}{3}Content-Disposition: form-data; name=\" {1}\" {3}{3}{2}{3}" ;
247250
248- return string . Format ( format , FormBoundary , param . Name , param . Value , LineBreak , param . ContentType ) ;
251+ return string . Format ( format , FormBoundary , param . Name , param . Value , LineBreak , param . ContentType ! ) ;
249252 }
250253
251254 string GetMultipartFooter ( ) => $ "--{ FormBoundary } --{ LineBreak } ";
@@ -257,8 +260,13 @@ void PreparePostBody(WebRequest webRequest)
257260 if ( HasFiles || AlwaysMultipartFormData )
258261 {
259262 if ( needsContentType )
260- webRequest . ContentType = GetMultipartFormContentType ( ) ;
261- else if ( ! webRequest . ContentType . Contains ( "boundary" ) ) webRequest . ContentType = webRequest . ContentType + "; boundary=" + FormBoundary ;
263+ {
264+ webRequest . ContentType = GetMultipartFormContentType ( ) ;
265+ }
266+ else if ( ! webRequest . ContentType . Contains ( "boundary" ) )
267+ {
268+ webRequest . ContentType = webRequest . ContentType + "; boundary=" + FormBoundary ;
269+ }
262270 }
263271 else if ( HasBody )
264272 {
@@ -309,6 +317,7 @@ HttpResponse ExtractResponseData(HttpWebResponse webResponse)
309317
310318 if ( webResponse . Cookies != null )
311319 foreach ( Cookie cookie in webResponse . Cookies )
320+ {
312321 response . Cookies . Add (
313322 new HttpCookie
314323 {
@@ -328,12 +337,15 @@ HttpResponse ExtractResponseData(HttpWebResponse webResponse)
328337 Version = cookie . Version
329338 }
330339 ) ;
340+ }
331341
332342 response . Headers = webResponse . Headers . AllKeys
333- . Select ( x => new HttpHeader ( x , webResponse . Headers [ x ] ) ) . ToList ( ) ;
343+ . Select ( x => new HttpHeader ( x , webResponse . Headers [ x ] ) )
344+ . ToList ( ) ;
334345
335346 var webResponseStream = webResponse . GetResponseStream ( ) ;
336- ProcessResponseStream ( ) ;
347+ if ( webResponseStream != null )
348+ ProcessResponseStream ( ) ;
337349
338350 webResponse . Close ( ) ;
339351 return response ;
0 commit comments