Skip to content

Commit 084ca2b

Browse files
committed
Stream supports any content type
1 parent 2e0c343 commit 084ca2b

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/Client/Plumbing/HttpClientWrapper.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,7 @@ void CheckSuccess(string content)
221221
? JsonConvert.DeserializeObject<T>(json, JsonSerializerSettings)
222222
: default(T);
223223

224-
case "application/octet-stream":
225-
case "image/png":
226-
CheckSuccess("<Stream>");
227-
if (typeof(T) != typeof(Stream))
228-
throw new Exception("API returned file, but no file was expected");
229-
return readResponse
230-
? (T) (object) await response.Content.ReadAsStreamAsync()
231-
: default(T);
224+
232225

233226
case "text/csv":
234227
var csv = await response.Content.ReadAsStringAsync();
@@ -237,6 +230,14 @@ void CheckSuccess(string content)
237230
throw new Exception($"API returned csv, but expected type is {typeof(T)}");
238231
return (T) (object) csv;
239232
default:
233+
if (typeof(T) == typeof(Stream))
234+
{
235+
CheckSuccess("<Stream>");
236+
return readResponse
237+
? (T)(object)await response.Content.ReadAsStreamAsync()
238+
: default(T);
239+
}
240+
240241
var content = await response.Content.ReadAsStringAsync();
241242
CheckSuccess(content);
242243

0 commit comments

Comments
 (0)