Esempio n. 1
0
        /// <summary>
        /// Configures the service collection for the webhost.
        /// </summary>
        /// <param name="services">The service collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCompression();
            services.AddHttpContextAccessor();
            services.AddHttpsRedirection(options =>
            {
                options.HttpsPort = _serverApplicationHost.HttpsPort;
            });

            // TODO remove once this is fixed upstream https://github.com/dotnet/aspnetcore/issues/34371
            services.AddSingleton <IActionResultExecutor <PhysicalFileResult>, SymlinkFollowingPhysicalFileResultExecutor>();
            services.AddJellyfinApi(_serverApplicationHost.GetApiPluginAssemblies(), _serverConfigurationManager.GetNetworkConfiguration());

            services.AddJellyfinApiSwagger();

            // configure custom legacy authentication
            services.AddCustomAuthentication();

            services.AddJellyfinApiAuthorization();

            var productHeader = new ProductInfoHeaderValue(
                _serverApplicationHost.Name.Replace(' ', '-'),
                _serverApplicationHost.ApplicationVersionString);
            var acceptJsonHeader = new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json, 1.0);
            var acceptXmlHeader  = new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Xml, 0.9);
            var acceptAnyHeader  = new MediaTypeWithQualityHeaderValue("*/*", 0.8);
            Func <IServiceProvider, HttpMessageHandler> defaultHttpClientHandlerDelegate = (_) => new SocketsHttpHandler()
            {
                AutomaticDecompression        = DecompressionMethods.All,
                RequestHeaderEncodingSelector = (_, _) => Encoding.UTF8
            };

            services
            .AddHttpClient(NamedClient.Default, c =>
            {
                c.DefaultRequestHeaders.UserAgent.Add(productHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptJsonHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptXmlHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
            })
            .ConfigurePrimaryHttpMessageHandler(defaultHttpClientHandlerDelegate);

            services.AddHttpClient(NamedClient.MusicBrainz, c =>
            {
                c.DefaultRequestHeaders.UserAgent.Add(productHeader);
                c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({_serverApplicationHost.ApplicationUserAgentAddress})"));
                c.DefaultRequestHeaders.Accept.Add(acceptXmlHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
            })
            .ConfigurePrimaryHttpMessageHandler(defaultHttpClientHandlerDelegate);

            services.AddHealthChecks()
            .AddDbContextCheck <JellyfinDb>();

            services.AddHlsPlaylistGenerator();
        }
Esempio n. 2
0
        /// <summary>
        /// Configures the service collection for the webhost.
        /// </summary>
        /// <param name="services">The service collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCompression();
            services.AddHttpContextAccessor();
            services.AddHttpsRedirection(options =>
            {
                options.HttpsPort = _serverApplicationHost.HttpsPort;
            });
            services.AddJellyfinApi(_serverApplicationHost.GetApiPluginAssemblies(), _serverConfigurationManager.GetNetworkConfiguration().KnownProxies);

            services.AddJellyfinApiSwagger();

            // configure custom legacy authentication
            services.AddCustomAuthentication();

            services.AddJellyfinApiAuthorization();

            var productHeader = new ProductInfoHeaderValue(
                _serverApplicationHost.Name.Replace(' ', '-'),
                _serverApplicationHost.ApplicationVersionString);
            var acceptJsonHeader = new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json, 1.0);
            var acceptXmlHeader  = new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Xml, 0.9);
            var acceptAnyHeader  = new MediaTypeWithQualityHeaderValue("*/*", 0.8);

            services
            .AddHttpClient(NamedClient.Default, c =>
            {
                c.DefaultRequestHeaders.UserAgent.Add(productHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptJsonHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptXmlHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
            })
            .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler());

            services.AddHttpClient(NamedClient.MusicBrainz, c =>
            {
                c.DefaultRequestHeaders.UserAgent.Add(productHeader);
                c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({_serverApplicationHost.ApplicationUserAgentAddress})"));
                c.DefaultRequestHeaders.Accept.Add(acceptJsonHeader);
                c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
            })
            .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler());

            services.AddHealthChecks()
            .AddDbContextCheck <JellyfinDb>();
        }
Esempio n. 3
0
        /// <summary>
        /// Configures the service collection for the webhost.
        /// </summary>
        /// <param name="services">The service collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCompression();
            services.AddHttpContextAccessor();
            services.AddHttpsRedirection(options =>
            {
                options.HttpsPort = _serverApplicationHost.HttpsPort;
            });
            services.AddJellyfinApi(
                _serverConfigurationManager.Configuration.BaseUrl.TrimStart('/'),
                _serverApplicationHost.GetApiPluginAssemblies());

            services.AddJellyfinApiSwagger();

            // configure custom legacy authentication
            services.AddCustomAuthentication();

            services.AddJellyfinApiAuthorization();

            var productHeader = new ProductInfoHeaderValue(
                _serverApplicationHost.Name.Replace(' ', '-'),
                _serverApplicationHost.ApplicationVersionString);

            services
            .AddHttpClient(NamedClient.Default, c =>
            {
                c.DefaultRequestHeaders.UserAgent.Add(productHeader);
            })
            .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler());

            services.AddHttpClient(NamedClient.MusicBrainz, c =>
            {
                c.DefaultRequestHeaders.UserAgent.Add(productHeader);
                c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({_serverApplicationHost.ApplicationUserAgentAddress})"));
            })
            .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler());

            services.AddHealthChecks()
            .AddDbContextCheck <JellyfinDb>();
        }