mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
fix: "zip" Content-Type resulting in null Stream for Artifacts on Blob Storage (#2905)
This commit is contained in:
@@ -177,6 +177,27 @@ namespace Octokit.Tests.Http
|
||||
|
||||
Assert.Equal("application/json", response.ContentType);
|
||||
}
|
||||
|
||||
// See #2898 for why this is necessary
|
||||
// Non standard MIME Content-Type coming from Blob Storage when downloading artifacts
|
||||
[Fact]
|
||||
public async Task SetsZipContentType()
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
var streamContent = new StreamContent(memoryStream);
|
||||
streamContent.Headers.TryAddWithoutValidation("Content-Type", "zip");
|
||||
|
||||
var responseMessage = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK,
|
||||
Content = streamContent
|
||||
};
|
||||
var tester = new HttpClientAdapterTester();
|
||||
|
||||
var response = await tester.BuildResponseTester(responseMessage);
|
||||
|
||||
Assert.Equal("application/zip", response.ContentType);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class HttpClientAdapterTester : HttpClientAdapter
|
||||
|
||||
@@ -81,7 +81,6 @@ namespace Octokit.Internal
|
||||
AcceptHeaders.RawContentMediaType,
|
||||
"application/zip" ,
|
||||
"application/x-gzip" ,
|
||||
"zip" , // Not a standard MIME type but see issue #2898
|
||||
"application/octet-stream"};
|
||||
|
||||
var content = responseMessage.Content;
|
||||
@@ -169,10 +168,18 @@ namespace Octokit.Internal
|
||||
|
||||
static string GetContentMediaType(HttpContent httpContent)
|
||||
{
|
||||
if (httpContent.Headers != null && httpContent.Headers.ContentType != null)
|
||||
if (httpContent.Headers?.ContentType != null)
|
||||
{
|
||||
return httpContent.Headers.ContentType.MediaType;
|
||||
}
|
||||
|
||||
// Issue #2898 - Bad "zip" Content-Type coming from Blob Storage for artifacts
|
||||
if (httpContent.Headers?.TryGetValues("Content-Type", out var contentTypeValues) == true
|
||||
&& contentTypeValues.FirstOrDefault() == "zip")
|
||||
{
|
||||
return "application/zip";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user