From 2d06095447b972c8c7239277428e2c67c8b7ca86 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 25 Feb 2013 22:43:04 -0500 Subject: plugin security fixes and other abstractions --- MediaBrowser.Networking/HttpServer/HttpServer.cs | 43 +++++++++++------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'MediaBrowser.Networking/HttpServer/HttpServer.cs') diff --git a/MediaBrowser.Networking/HttpServer/HttpServer.cs b/MediaBrowser.Networking/HttpServer/HttpServer.cs index b6250527d..08a6b3561 100644 --- a/MediaBrowser.Networking/HttpServer/HttpServer.cs +++ b/MediaBrowser.Networking/HttpServer/HttpServer.cs @@ -1,4 +1,3 @@ -using System.Net.WebSockets; using Funq; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Kernel; @@ -16,10 +15,12 @@ using ServiceStack.WebHost.Endpoints; using ServiceStack.WebHost.Endpoints.Extensions; using ServiceStack.WebHost.Endpoints.Support; using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Net; +using System.Net.WebSockets; using System.Reactive.Linq; using System.Reflection; using System.Text; @@ -44,10 +45,9 @@ namespace MediaBrowser.Networking.HttpServer public string UrlPrefix { get; private set; } /// - /// Gets or sets the kernel. + /// The _rest services /// - /// The kernel. - private IKernel Kernel { get; set; } + private readonly List _restServices = new List(); /// /// Gets or sets the application host. @@ -88,19 +88,14 @@ namespace MediaBrowser.Networking.HttpServer /// Initializes a new instance of the class. /// /// The application host. - /// The kernel. /// The protobuf serializer. /// The logger. /// Name of the server. /// The default redirectpath. /// urlPrefix - public HttpServer(IApplicationHost applicationHost, IKernel kernel, IProtobufSerializer protobufSerializer, ILogger logger, string serverName, string defaultRedirectpath) + public HttpServer(IApplicationHost applicationHost, IProtobufSerializer protobufSerializer, ILogger logger, string serverName, string defaultRedirectpath) : base() { - if (kernel == null) - { - throw new ArgumentNullException("kernel"); - } if (protobufSerializer == null) { throw new ArgumentNullException("protobufSerializer"); @@ -130,13 +125,6 @@ namespace MediaBrowser.Networking.HttpServer EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null; EndpointHostConfig.Instance.MetadataRedirectPath = "metadata"; - - Kernel = kernel; - - EndpointHost.ConfigureHost(this, ServerName, CreateServiceManager()); - ContentTypeFilters.Register(ContentType.ProtoBuf, (reqCtx, res, stream) => ProtobufSerializer.SerializeToStream(res, stream), (type, stream) => ProtobufSerializer.DeserializeFromStream(stream, type)); - - Init(); } /// @@ -161,11 +149,6 @@ namespace MediaBrowser.Networking.HttpServer container.Adapter = new ContainerAdapter(ApplicationHost); - foreach (var service in Kernel.RestServices) - { - service.Configure(this); - } - Plugins.Add(new SwaggerFeature()); Plugins.Add(new CorsFeature()); @@ -450,7 +433,7 @@ namespace MediaBrowser.Networking.HttpServer /// ServiceManager. protected override ServiceManager CreateServiceManager(params Assembly[] assembliesWithServices) { - var types = Kernel.RestServices.Select(r => r.GetType()).ToArray(); + var types = _restServices.Select(r => r.GetType()).ToArray(); return new ServiceManager(new Container(), new ServiceController(() => types)); } @@ -511,6 +494,20 @@ namespace MediaBrowser.Networking.HttpServer /// /// true if [enable HTTP request logging]; otherwise, false. public bool EnableHttpRequestLogging { get; set; } + + /// + /// Adds the rest handlers. + /// + /// The services. + public void Init(IEnumerable services) + { + _restServices.AddRange(services); + + EndpointHost.ConfigureHost(this, ServerName, CreateServiceManager()); + ContentTypeFilters.Register(ContentType.ProtoBuf, (reqCtx, res, stream) => ProtobufSerializer.SerializeToStream(res, stream), (type, stream) => ProtobufSerializer.DeserializeFromStream(stream, type)); + + Init(); + } } /// -- cgit v1.2.3