Skip to content

Commit

Permalink
Properly dispose HttpWebResponse in SecurityPolicyTests (#5468) (#5475)
Browse files Browse the repository at this point in the history
  • Loading branch information
skofman1 committed Feb 14, 2018
1 parent e21bad6 commit 22ea656
Showing 1 changed file with 13 additions and 9 deletions.
Expand Up @@ -206,15 +206,17 @@ private async Task<string> CreateVerificationKey(string apiKey, string packageId
request.Headers.Add(Constants.NuGetHeaderApiKey, apiKey);
request.Headers.Add(Constants.NuGetHeaderClientVersion, "NuGetGallery.FunctionalTests");

var response = await request.GetResponseAsync() as HttpWebResponse;
Assert.NotNull(response);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

string responseText;
using (var sr = new StreamReader(response.GetResponseStream()))
using (var response = await request.GetResponseAsync() as HttpWebResponse)
{
responseText = await sr.ReadToEndAsync();
}
Assert.NotNull(response);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

using (var sr = new StreamReader(response.GetResponseStream()))
{
responseText = await sr.ReadToEndAsync();
}
}

var json = JObject.Parse(responseText);
var expiration = json.Value<DateTime>("Expires");
Expand All @@ -236,8 +238,10 @@ private async Task<HttpStatusCode> VerifyPackageKey(string apiKey, string packag

try
{
var response = await request.GetResponseAsync() as HttpWebResponse;
return response.StatusCode;
using (var response = await request.GetResponseAsync() as HttpWebResponse)
{
return response.StatusCode;
}
}
catch (WebException e)
{
Expand Down

0 comments on commit 22ea656

Please sign in to comment.