Fixes for Downloading ReleaseAsset zip File #854

This commit  addressed the `BuildResponse`  wasn't handling
response `content-type` `application/octet-stream` for binary items.
This commit is contained in:
Naveen
2015-10-16 14:29:43 -04:00
parent 068511b116
commit 1886629e6f
4 changed files with 54 additions and 5 deletions
+10 -4
View File
@@ -70,16 +70,22 @@ namespace Octokit.Internal
object responseBody = null;
string contentType = null;
// We added support for downloading images,zip-files and application/octet-stream.
// Let's constrain this appropriately.
var binaryContentTypes = new[] {"application/zip"
,"application/x-gzip",
"application/octet-stream"};
using (var content = responseMessage.Content)
{
if (content != null)
{
contentType = GetContentMediaType(responseMessage.Content);
// We added support for downloading images and zip-files. Let's constrain this appropriately.
if (contentType != null && (contentType.StartsWith("image/")
|| contentType.Equals("application/zip", StringComparison.OrdinalIgnoreCase)
|| contentType.Equals("application/x-gzip", StringComparison.OrdinalIgnoreCase)))
if (contentType != null && (contentType.StartsWith("image/") ||
binaryContentTypes
.Any(item => item.Equals(contentType,StringComparison.OrdinalIgnoreCase))))
{
responseBody = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}