From 37dec8491ca764a386e6be404b6c091891faaf16 Mon Sep 17 00:00:00 2001 From: Haacked Date: Wed, 31 Dec 2014 20:45:42 -0800 Subject: [PATCH] Read binary data based on response content type The HttpClientAdapter class shouldn't need to know anything about the type we'll eventually deserialize to. In fact, reading binary data was a little hack added _only_ to support images such as emoji and not for general purpose content. --- Octokit/Http/HttpClientAdapter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 5d59c212..1e42c4f8 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -69,7 +69,10 @@ namespace Octokit.Internal { if (content != null) { - if (typeof(T) != typeof(byte[])) + var mediaType = responseMessage.Content.Headers.ContentType.MediaType; + + // We added support for downloading images. Let's constrain this appropriately. + if (!mediaType.StartsWith("image/")) { responseBody = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); }