diff options
Diffstat (limited to 'Emby.Server.Implementations/HttpServer')
| -rw-r--r-- | Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 41 | ||||
| -rw-r--r-- | Emby.Server.Implementations/HttpServer/HttpResultFactory.cs | 3 |
2 files changed, 23 insertions, 21 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 99ec146d7..c65289e13 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -2,7 +2,6 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Logging; -using ServiceStack; using System; using System.Collections.Generic; using System.IO; @@ -29,7 +28,7 @@ using SocketHttpListener.Primitives; namespace Emby.Server.Implementations.HttpServer { - public class HttpListenerHost : ServiceStackHost, IHttpServer + public class HttpListenerHost : IHttpServer, IDisposable { private string DefaultRedirectPath { get; set; } @@ -62,7 +61,10 @@ namespace Emby.Server.Implementations.HttpServer private readonly bool _enableDualModeSockets; public List<Action<IRequest, IResponse, object>> RequestFilters { get; set; } - private Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>(); + public List<Action<IRequest, IResponse, object>> ResponseFilters { get; set; } + + private readonly Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>(); + public static HttpListenerHost Instance { get; protected set; } public HttpListenerHost(IServerApplicationHost applicationHost, ILogger logger, @@ -71,6 +73,8 @@ namespace Emby.Server.Implementations.HttpServer string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer, IEnvironmentInfo environment, ICertificate certificate, IStreamFactory streamFactory, Func<Type, Func<string, object>> funcParseFn, bool enableDualModeSockets) : base() { + Instance = this; + _appHost = applicationHost; DefaultRedirectPath = defaultRedirectPath; _networkManager = networkManager; @@ -90,6 +94,7 @@ namespace Emby.Server.Implementations.HttpServer _logger = logger; RequestFilters = new List<Action<IRequest, IResponse, object>>(); + ResponseFilters = new List<Action<IRequest, IResponse, object>>(); } public string GlobalResponse { get; set; } @@ -112,7 +117,7 @@ namespace Emby.Server.Implementations.HttpServer } } - public override object CreateInstance(Type type) + public object CreateInstance(Type type) { return _appHost.CreateInstance(type); } @@ -168,12 +173,12 @@ namespace Emby.Server.Implementations.HttpServer private IHasRequestFilter[] GetRequestFilterAttributes(Type requestDtoType) { - var attributes = requestDtoType.AllAttributes().OfType<IHasRequestFilter>().ToList(); + var attributes = requestDtoType.GetTypeInfo().GetCustomAttributes(true).OfType<IHasRequestFilter>().ToList(); var serviceType = GetServiceTypeByRequest(requestDtoType); if (serviceType != null) { - attributes.AddRange(serviceType.AllAttributes().OfType<IHasRequestFilter>()); + attributes.AddRange(serviceType.GetTypeInfo().GetCustomAttributes(true).OfType<IHasRequestFilter>()); } attributes.Sort((x, y) => x.Priority - y.Priority); @@ -611,7 +616,7 @@ namespace Emby.Server.Implementations.HttpServer _logger.Error("Path parts empty for PathInfo: {0}, Url: {1}", pathInfo, httpReq.RawUrl); return null; } - + string contentType; var restPath = ServiceHandler.FindMatchingRestPath(httpReq.HttpMethod, pathInfo, _logger, out contentType); @@ -658,8 +663,6 @@ namespace Emby.Server.Implementations.HttpServer _logger.Info("Calling ServiceStack AppHost.Init"); - Instance = this; - ServiceController.Init(this); var requestFilters = _appHost.GetExports<IRequestFilter>().ToList(); @@ -668,12 +671,12 @@ namespace Emby.Server.Implementations.HttpServer RequestFilters.Add(filter.Filter); } - GlobalResponseFilters.Add(new ResponseFilter(_logger).FilterResponse); + ResponseFilters.Add(new ResponseFilter(_logger).FilterResponse); } - public override RouteAttribute[] GetRouteAttributes(Type requestType) + public RouteAttribute[] GetRouteAttributes(Type requestType) { - var routes = requestType.AllAttributes<RouteAttribute>(); + var routes = requestType.GetTypeInfo().GetCustomAttributes<RouteAttribute>(true).ToList(); var clone = routes.ToList(); foreach (var route in clone) @@ -703,27 +706,27 @@ namespace Emby.Server.Implementations.HttpServer return routes.ToArray(); } - public override Func<string, object> GetParseFn(Type propertyType) + public Func<string, object> GetParseFn(Type propertyType) { return _funcParseFn(propertyType); } - public override void SerializeToJson(object o, Stream stream) + public void SerializeToJson(object o, Stream stream) { _jsonSerializer.SerializeToStream(o, stream); } - public override void SerializeToXml(object o, Stream stream) + public void SerializeToXml(object o, Stream stream) { _xmlSerializer.SerializeToStream(o, stream); } - public override object DeserializeXml(Type type, Stream stream) + public object DeserializeXml(Type type, Stream stream) { return _xmlSerializer.DeserializeFromStream(type, stream); } - public override object DeserializeJson(Type type, Stream stream) + public object DeserializeJson(Type type, Stream stream) { return _jsonSerializer.DeserializeFromStream(stream, type); } @@ -764,7 +767,7 @@ namespace Emby.Server.Implementations.HttpServer { if (_disposed) return; - base.Dispose(); + Dispose(); lock (_disposeLock) { @@ -779,7 +782,7 @@ namespace Emby.Server.Implementations.HttpServer } } - public override void Dispose() + public void Dispose() { Dispose(true); GC.SuppressFinalize(this); diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index 3f756fc7a..6bfd83110 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -16,7 +16,6 @@ using Emby.Server.Implementations.HttpServer; using Emby.Server.Implementations.Services; using MediaBrowser.Model.IO; using MediaBrowser.Model.Services; -using ServiceStack; using IRequest = MediaBrowser.Model.Services.IRequest; using MimeTypes = MediaBrowser.Model.Net.MimeTypes; using StreamWriter = Emby.Server.Implementations.HttpServer.StreamWriter; @@ -204,7 +203,7 @@ namespace Emby.Server.Implementations.HttpServer using (var ms = new MemoryStream()) { var contentType = request.ResponseContentType; - var writerFn = RequestHelper.GetResponseWriter(contentType); + var writerFn = RequestHelper.GetResponseWriter(HttpListenerHost.Instance, contentType); writerFn(dto, ms); |
