diff --git a/Octokit.Tests/Http/ConnectionTests.cs b/Octokit.Tests/Http/ConnectionTests.cs index 30747fdf..4e9de6f6 100644 --- a/Octokit.Tests/Http/ConnectionTests.cs +++ b/Octokit.Tests/Http/ConnectionTests.cs @@ -111,9 +111,9 @@ namespace Octokit.Tests.Http string headerKey, string otpHeaderValue) { + var headers = new Dictionary { { headerKey, otpHeaderValue } }; var httpClient = Substitute.For(); - IResponse response = new Response { StatusCode = HttpStatusCode.Unauthorized }; - response.Headers[headerKey] = otpHeaderValue; + IResponse response = new Response(HttpStatusCode.Unauthorized, null, headers, "application/json"); httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response)); var connection = new Connection(new ProductHeaderValue("OctokitTests"), _exampleUri, @@ -138,12 +138,9 @@ namespace Octokit.Tests.Http string otpHeaderValue, TwoFactorType expectedFactorType) { + var headers = new Dictionary { { headerKey, otpHeaderValue } }; + IResponse response = new Response(HttpStatusCode.Unauthorized, null, headers, "application/json"); var httpClient = Substitute.For(); - IResponse response = new Response - { - StatusCode = HttpStatusCode.Unauthorized, - }; - response.Headers[headerKey] = otpHeaderValue; httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response)); var connection = new Connection(new ProductHeaderValue("OctokitTests"), _exampleUri, diff --git a/Octokit/Http/ApiResponse.cs b/Octokit/Http/ApiResponse.cs index e68f8a6f..07252b64 100644 --- a/Octokit/Http/ApiResponse.cs +++ b/Octokit/Http/ApiResponse.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; +using System.Collections.Generic; using System.Net; namespace Octokit.Internal @@ -17,7 +15,7 @@ namespace Octokit.Internal var body = response.Body is T ? (T)response.Body : default(T); HttpResponse = response; - Headers = new ReadOnlyDictionary(response.Headers); + Headers = response.Headers; Body = body; ApiInfo = response.ApiInfo; StatusCode = response.StatusCode; diff --git a/Octokit/Http/IResponse.cs b/Octokit/Http/IResponse.cs index 1cb48260..0d885e36 100644 --- a/Octokit/Http/IResponse.cs +++ b/Octokit/Http/IResponse.cs @@ -18,7 +18,7 @@ namespace Octokit public interface IResponse { object Body { get; } - IDictionary Headers { get; } + IReadOnlyDictionary Headers { get; } ApiInfo ApiInfo { get; } HttpStatusCode StatusCode { get; } string ContentType { get; } diff --git a/Octokit/Http/Response.cs b/Octokit/Http/Response.cs index 0d01ce79..919f13ca 100644 --- a/Octokit/Http/Response.cs +++ b/Octokit/Http/Response.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Net; -using System.Net.Http; using Octokit.Internal; namespace Octokit.Internal @@ -17,7 +15,7 @@ namespace Octokit.Internal { Ensure.ArgumentNotNull(headers, "headers"); - Headers = headers; + Headers = new ReadOnlyDictionary(headers); ApiInfo = ApiInfoParser.ParseResponseHeaders(headers); } @@ -27,13 +25,13 @@ namespace Octokit.Internal StatusCode = statusCode; Body = body; - Headers = headers; + Headers = new ReadOnlyDictionary(headers); ApiInfo = ApiInfoParser.ParseResponseHeaders(headers); ContentType = contentType; } public object Body { get; set; } - public IDictionary Headers { get; private set; } + public IReadOnlyDictionary Headers { get; private set; } public ApiInfo ApiInfo { get; private set; } public HttpStatusCode StatusCode { get; set; } public string ContentType { get; private set; }