@@ -193,7 +193,7 @@ public virtual Response Execute(Command commandToExecute)
193
193
string unknownErrorMessage = "An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL {0}. The exception message was: {1}" ;
194
194
throw new WebDriverException ( string . Format ( CultureInfo . InvariantCulture , unknownErrorMessage , requestInfo . FullUri . AbsoluteUri , ex . Message ) , ex ) ;
195
195
}
196
- catch ( TaskCanceledException ex )
196
+ catch ( TaskCanceledException ex )
197
197
{
198
198
string timeoutMessage = "The HTTP request to the remote WebDriver server for URL {0} timed out after {1} seconds." ;
199
199
throw new WebDriverException ( string . Format ( CultureInfo . InvariantCulture , timeoutMessage , requestInfo . FullUri . AbsoluteUri , this . serverResponseTimeout . TotalSeconds ) , ex ) ;
@@ -253,34 +253,39 @@ private async Task<HttpResponseInfo> MakeHttpRequest(HttpRequestInfo requestInfo
253
253
this . OnSendingRemoteHttpRequest ( eventArgs ) ;
254
254
255
255
HttpMethod method = new HttpMethod ( requestInfo . HttpMethod ) ;
256
- HttpRequestMessage requestMessage = new HttpRequestMessage ( method , requestInfo . FullUri ) ;
257
- if ( requestInfo . HttpMethod == HttpCommandInfo . GetCommand )
256
+ using ( HttpRequestMessage requestMessage = new HttpRequestMessage ( method , requestInfo . FullUri ) )
258
257
{
259
- CacheControlHeaderValue cacheControlHeader = new CacheControlHeaderValue ( ) ;
260
- cacheControlHeader . NoCache = true ;
261
- requestMessage . Headers . CacheControl = cacheControlHeader ;
262
- }
258
+ if ( requestInfo . HttpMethod == HttpCommandInfo . GetCommand )
259
+ {
260
+ CacheControlHeaderValue cacheControlHeader = new CacheControlHeaderValue ( ) ;
261
+ cacheControlHeader . NoCache = true ;
262
+ requestMessage . Headers . CacheControl = cacheControlHeader ;
263
+ }
263
264
264
- if ( requestInfo . HttpMethod == HttpCommandInfo . PostCommand )
265
- {
266
- MediaTypeWithQualityHeaderValue acceptHeader = new MediaTypeWithQualityHeaderValue ( JsonMimeType ) ;
267
- acceptHeader . CharSet = Utf8CharsetType ;
268
- requestMessage . Headers . Accept . Add ( acceptHeader ) ;
265
+ if ( requestInfo . HttpMethod == HttpCommandInfo . PostCommand )
266
+ {
267
+ MediaTypeWithQualityHeaderValue acceptHeader = new MediaTypeWithQualityHeaderValue ( JsonMimeType ) ;
268
+ acceptHeader . CharSet = Utf8CharsetType ;
269
+ requestMessage . Headers . Accept . Add ( acceptHeader ) ;
269
270
270
- byte [ ] bytes = Encoding . UTF8 . GetBytes ( eventArgs . RequestBody ) ;
271
- requestMessage . Content = new ByteArrayContent ( bytes , 0 , bytes . Length ) ;
271
+ byte [ ] bytes = Encoding . UTF8 . GetBytes ( eventArgs . RequestBody ) ;
272
+ requestMessage . Content = new ByteArrayContent ( bytes , 0 , bytes . Length ) ;
272
273
273
- MediaTypeHeaderValue contentTypeHeader = new MediaTypeHeaderValue ( JsonMimeType ) ;
274
- contentTypeHeader . CharSet = Utf8CharsetType ;
275
- requestMessage . Content . Headers . ContentType = contentTypeHeader ;
276
- }
274
+ MediaTypeHeaderValue contentTypeHeader = new MediaTypeHeaderValue ( JsonMimeType ) ;
275
+ contentTypeHeader . CharSet = Utf8CharsetType ;
276
+ requestMessage . Content . Headers . ContentType = contentTypeHeader ;
277
+ }
278
+
279
+ using ( HttpResponseMessage responseMessage = await this . client . SendAsync ( requestMessage ) )
280
+ {
281
+ HttpResponseInfo httpResponseInfo = new HttpResponseInfo ( ) ;
282
+ httpResponseInfo . Body = await responseMessage . Content . ReadAsStringAsync ( ) ;
283
+ httpResponseInfo . ContentType = responseMessage . Content . Headers . ContentType . ToString ( ) ;
284
+ httpResponseInfo . StatusCode = responseMessage . StatusCode ;
277
285
278
- HttpResponseMessage responseMessage = await this . client . SendAsync ( requestMessage ) ;
279
- HttpResponseInfo httpResponseInfo = new HttpResponseInfo ( ) ;
280
- httpResponseInfo . Body = await responseMessage . Content . ReadAsStringAsync ( ) ;
281
- httpResponseInfo . ContentType = responseMessage . Content . Headers . ContentType . ToString ( ) ;
282
- httpResponseInfo . StatusCode = responseMessage . StatusCode ;
283
- return httpResponseInfo ;
286
+ return httpResponseInfo ;
287
+ }
288
+ }
284
289
}
285
290
286
291
private Response CreateResponse ( HttpResponseInfo responseInfo )
0 commit comments