|
|
@ -90,7 +90,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private IHasHeaders GetHttpResult(IRequest requestContext, Stream content, string contentType, bool addCachePrevention, IDictionary<string, string> responseHeaders = null)
|
|
|
|
private IHasHeaders GetHttpResult(IRequest requestContext, Stream content, string contentType, bool addCachePrevention, IDictionary<string, string> responseHeaders = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = new StreamWriter(content, contentType, _logger);
|
|
|
|
var result = new StreamWriter(content, contentType);
|
|
|
|
|
|
|
|
|
|
|
|
if (responseHeaders == null)
|
|
|
|
if (responseHeaders == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -131,7 +131,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
content = Array.Empty<byte>();
|
|
|
|
content = Array.Empty<byte>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = new StreamWriter(content, contentType, contentLength, _logger);
|
|
|
|
result = new StreamWriter(content, contentType, contentLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -143,7 +143,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
responseHeaders = new Dictionary<string, string>();
|
|
|
|
responseHeaders = new Dictionary<string, string>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string expires))
|
|
|
|
if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string _))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
responseHeaders["Expires"] = "-1";
|
|
|
|
responseHeaders["Expires"] = "-1";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -175,7 +175,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
bytes = Array.Empty<byte>();
|
|
|
|
bytes = Array.Empty<byte>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = new StreamWriter(bytes, contentType, contentLength, _logger);
|
|
|
|
result = new StreamWriter(bytes, contentType, contentLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -187,7 +187,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
responseHeaders = new Dictionary<string, string>();
|
|
|
|
responseHeaders = new Dictionary<string, string>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string expires))
|
|
|
|
if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string _))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
responseHeaders["Expires"] = "-1";
|
|
|
|
responseHeaders["Expires"] = "-1";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -277,9 +277,9 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
|
|
|
|
|
|
|
|
private object ToOptimizedResultInternal<T>(IRequest request, T dto, IDictionary<string, string> responseHeaders = null)
|
|
|
|
private object ToOptimizedResultInternal<T>(IRequest request, T dto, IDictionary<string, string> responseHeaders = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var contentType = request.ResponseContentType;
|
|
|
|
var contentType = request.ResponseContentType?.Split(';')[0];
|
|
|
|
|
|
|
|
|
|
|
|
switch (GetRealContentType(contentType))
|
|
|
|
switch (contentType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case "application/xml":
|
|
|
|
case "application/xml":
|
|
|
|
case "text/xml":
|
|
|
|
case "text/xml":
|
|
|
@ -333,13 +333,13 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
|
|
|
|
|
|
|
|
if (isHeadRequest)
|
|
|
|
if (isHeadRequest)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = new StreamWriter(Array.Empty<byte>(), contentType, contentLength, _logger);
|
|
|
|
var result = new StreamWriter(Array.Empty<byte>(), contentType, contentLength);
|
|
|
|
AddResponseHeaders(result, responseHeaders);
|
|
|
|
AddResponseHeaders(result, responseHeaders);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = new StreamWriter(content, contentType, contentLength, _logger);
|
|
|
|
var result = new StreamWriter(content, contentType, contentLength);
|
|
|
|
AddResponseHeaders(result, responseHeaders);
|
|
|
|
AddResponseHeaders(result, responseHeaders);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -348,13 +348,19 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
private byte[] Compress(byte[] bytes, string compressionType)
|
|
|
|
private byte[] Compress(byte[] bytes, string compressionType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.Equals(compressionType, "br", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (string.Equals(compressionType, "br", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
return CompressBrotli(bytes);
|
|
|
|
return CompressBrotli(bytes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.Equals(compressionType, "deflate", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (string.Equals(compressionType, "deflate", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
return Deflate(bytes);
|
|
|
|
return Deflate(bytes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.Equals(compressionType, "gzip", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (string.Equals(compressionType, "gzip", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
return GZip(bytes);
|
|
|
|
return GZip(bytes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException(compressionType);
|
|
|
|
throw new NotSupportedException(compressionType);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -390,13 +396,6 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetRealContentType(string contentType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return contentType == null
|
|
|
|
|
|
|
|
? null
|
|
|
|
|
|
|
|
: contentType.Split(';')[0].ToLowerInvariant().Trim();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static string SerializeToXmlString(object from)
|
|
|
|
private static string SerializeToXmlString(object from)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var ms = new MemoryStream())
|
|
|
|
using (var ms = new MemoryStream())
|
|
|
@ -621,7 +620,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var hasHeaders = new StreamWriter(stream, contentType, _logger)
|
|
|
|
var hasHeaders = new StreamWriter(stream, contentType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnComplete = options.OnComplete,
|
|
|
|
OnComplete = options.OnComplete,
|
|
|
|
OnError = options.OnError
|
|
|
|
OnError = options.OnError
|
|
|
|