|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
|
using MediaBrowser.Model.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
@ -13,14 +15,17 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ResponseFilter
|
|
|
|
|
{
|
|
|
|
|
private readonly IHttpServer _server;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ResponseFilter"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="server">The HTTP server.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public ResponseFilter(ILogger logger)
|
|
|
|
|
public ResponseFilter(IHttpServer server, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
_server = server;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -32,10 +37,16 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
public void FilterResponse(IRequest req, HttpResponse res, object dto)
|
|
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<string, string> header in _server.GetCorsHeaders(req))
|
|
|
|
|
{
|
|
|
|
|
res.Headers.Add(header.Key, header.Value);
|
|
|
|
|
}
|
|
|
|
|
// Try to prevent compatibility view
|
|
|
|
|
res.Headers.Add("Access-Control-Allow-Headers", "Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, Want-Digest, X-MediaBrowser-Token, X-Emby-Authorization");
|
|
|
|
|
res.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
|
|
|
res.Headers.Add("Access-Control-Allow-Origin", "*");
|
|
|
|
|
res.Headers["Access-Control-Allow-Headers"] = ("Accept, Accept-Language, Authorization, Cache-Control, " +
|
|
|
|
|
"Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, " +
|
|
|
|
|
"Content-Type, Cookie, Date, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, " +
|
|
|
|
|
"Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, Want-Digest, X-MediaBrowser-Token, " +
|
|
|
|
|
"X-Emby-Authorization");
|
|
|
|
|
|
|
|
|
|
if (dto is Exception exception)
|
|
|
|
|
{
|
|
|
|
|