File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,27 @@ public async Task SetsContentType()
177
177
178
178
Assert . Equal ( "application/json" , response . ContentType ) ;
179
179
}
180
+
181
+ // See #2898 for why this is necessary
182
+ // Non standard MIME Content-Type coming from Blob Storage when downloading artifacts
183
+ [ Fact ]
184
+ public async Task SetsZipContentType ( )
185
+ {
186
+ var memoryStream = new MemoryStream ( ) ;
187
+ var streamContent = new StreamContent ( memoryStream ) ;
188
+ streamContent . Headers . TryAddWithoutValidation ( "Content-Type" , "zip" ) ;
189
+
190
+ var responseMessage = new HttpResponseMessage
191
+ {
192
+ StatusCode = HttpStatusCode . OK ,
193
+ Content = streamContent
194
+ } ;
195
+ var tester = new HttpClientAdapterTester ( ) ;
196
+
197
+ var response = await tester . BuildResponseTester ( responseMessage ) ;
198
+
199
+ Assert . Equal ( "application/zip" , response . ContentType ) ;
200
+ }
180
201
}
181
202
182
203
sealed class HttpClientAdapterTester : HttpClientAdapter
Original file line number Diff line number Diff line change @@ -81,7 +81,6 @@ protected virtual async Task<IResponse> BuildResponse(HttpResponseMessage respon
81
81
AcceptHeaders . RawContentMediaType ,
82
82
"application/zip" ,
83
83
"application/x-gzip" ,
84
- "zip" , // Not a standard MIME type but see issue #2898
85
84
"application/octet-stream" } ;
86
85
87
86
var content = responseMessage . Content ;
@@ -169,10 +168,18 @@ protected virtual HttpRequestMessage BuildRequestMessage(IRequest request)
169
168
170
169
static string GetContentMediaType ( HttpContent httpContent )
171
170
{
172
- if ( httpContent . Headers != null && httpContent . Headers . ContentType != null )
171
+ if ( httpContent . Headers ? . ContentType != null )
173
172
{
174
173
return httpContent . Headers . ContentType . MediaType ;
175
174
}
175
+
176
+ // Issue #2898 - Bad "zip" Content-Type coming from Blob Storage for artifacts
177
+ if ( httpContent . Headers ? . TryGetValues ( "Content-Type" , out var contentTypeValues ) == true
178
+ && contentTypeValues . FirstOrDefault ( ) == "zip" )
179
+ {
180
+ return "application/zip" ;
181
+ }
182
+
176
183
return null ;
177
184
}
178
185
You can’t perform that action at this time.
0 commit comments