mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 19:37:55 +02:00
update ResponseHelper
This commit is contained in:
parent
a60c85f4f8
commit
29185eb9bd
1 changed files with 32 additions and 4 deletions
|
@ -141,16 +141,44 @@ namespace Emby.Server.Implementations.Services
|
||||||
response.ContentType += "; charset=utf-8";
|
response.ContentType += "; charset=utf-8";
|
||||||
}
|
}
|
||||||
|
|
||||||
var writeToOutputStreamResult = await WriteToOutputStream(response, result).ConfigureAwait(false);
|
var asyncStreamWriter = result as IAsyncStreamWriter;
|
||||||
if (writeToOutputStreamResult)
|
if (asyncStreamWriter != null)
|
||||||
{
|
{
|
||||||
|
await asyncStreamWriter.WriteToAsync(response.OutputStream, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var streamWriter = result as IStreamWriter;
|
||||||
|
if (streamWriter != null)
|
||||||
|
{
|
||||||
|
streamWriter.WriteTo(response.OutputStream);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var stream = result as Stream;
|
||||||
|
if (stream != null)
|
||||||
|
{
|
||||||
|
using (stream)
|
||||||
|
{
|
||||||
|
await stream.CopyToAsync(response.OutputStream).ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = result as byte[];
|
||||||
|
if (bytes != null)
|
||||||
|
{
|
||||||
|
response.ContentType = "application/octet-stream";
|
||||||
|
response.SetContentLength(bytes.Length);
|
||||||
|
|
||||||
|
await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseText = result as string;
|
var responseText = result as string;
|
||||||
if (responseText != null)
|
if (responseText != null)
|
||||||
{
|
{
|
||||||
var bytes = Encoding.UTF8.GetBytes(responseText);
|
bytes = Encoding.UTF8.GetBytes(responseText);
|
||||||
response.SetContentLength(bytes.Length);
|
response.SetContentLength(bytes.Length);
|
||||||
await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
|
await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue