|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
@ -20,6 +21,8 @@ namespace Emby.Server.Implementations.Services
|
|
|
|
|
{
|
|
|
|
|
response.StatusCode = (int)HttpStatusCode.NoContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.OriginalResponse.ContentLength = 0;
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -39,11 +42,6 @@ namespace Emby.Server.Implementations.Services
|
|
|
|
|
|
|
|
|
|
response.StatusCode = httpResult.Status;
|
|
|
|
|
response.StatusDescription = httpResult.StatusCode.ToString();
|
|
|
|
|
//if (string.IsNullOrEmpty(httpResult.ContentType))
|
|
|
|
|
//{
|
|
|
|
|
// httpResult.ContentType = defaultContentType;
|
|
|
|
|
//}
|
|
|
|
|
//response.ContentType = httpResult.ContentType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var responseOptions = result as IHasHeaders;
|
|
|
|
@ -53,6 +51,7 @@ namespace Emby.Server.Implementations.Services
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(responseHeaders.Key, "Content-Length", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
response.OriginalResponse.ContentLength = long.Parse(responseHeaders.Value, CultureInfo.InvariantCulture);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -72,51 +71,36 @@ namespace Emby.Server.Implementations.Services
|
|
|
|
|
response.ContentType += "; charset=utf-8";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var asyncStreamWriter = result as IAsyncStreamWriter;
|
|
|
|
|
if (asyncStreamWriter != null)
|
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
case IAsyncStreamWriter asyncStreamWriter:
|
|
|
|
|
return asyncStreamWriter.WriteToAsync(response.OutputStream, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var streamWriter = result as IStreamWriter;
|
|
|
|
|
if (streamWriter != null)
|
|
|
|
|
{
|
|
|
|
|
case IStreamWriter streamWriter:
|
|
|
|
|
streamWriter.WriteTo(response.OutputStream);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fileWriter = result as FileWriter;
|
|
|
|
|
if (fileWriter != null)
|
|
|
|
|
{
|
|
|
|
|
case FileWriter fileWriter:
|
|
|
|
|
return fileWriter.WriteToAsync(response, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stream = result as Stream;
|
|
|
|
|
if (stream != null)
|
|
|
|
|
{
|
|
|
|
|
case Stream stream:
|
|
|
|
|
return CopyStream(stream, response.OutputStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bytes = result as byte[];
|
|
|
|
|
if (bytes != null)
|
|
|
|
|
{
|
|
|
|
|
case byte[] bytes:
|
|
|
|
|
response.ContentType = "application/octet-stream";
|
|
|
|
|
response.OriginalResponse.ContentLength = bytes.Length;
|
|
|
|
|
|
|
|
|
|
if (bytes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
case string responseText:
|
|
|
|
|
var responseTextAsBytes = Encoding.UTF8.GetBytes(responseText);
|
|
|
|
|
response.OriginalResponse.ContentLength = responseTextAsBytes.Length;
|
|
|
|
|
|
|
|
|
|
var responseText = result as string;
|
|
|
|
|
if (responseText != null)
|
|
|
|
|
if (responseTextAsBytes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
bytes = Encoding.UTF8.GetBytes(responseText);
|
|
|
|
|
if (bytes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
|
|
|
|
|
return response.OutputStream.WriteAsync(responseTextAsBytes, 0, responseTextAsBytes.Length, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -143,14 +127,13 @@ namespace Emby.Server.Implementations.Services
|
|
|
|
|
ms.Position = 0;
|
|
|
|
|
|
|
|
|
|
var contentLength = ms.Length;
|
|
|
|
|
response.OriginalResponse.ContentLength = contentLength;
|
|
|
|
|
|
|
|
|
|
if (contentLength > 0)
|
|
|
|
|
{
|
|
|
|
|
await ms.CopyToAsync(response.OutputStream).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//serializer(result, outputStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|