<commit_before>﻿using DotOPDS.Middleware;
using DotOPDS.Utils;
using Microsoft.Owin.Builder;
using Nowin;
using Owin;
using System;
using System.Net;
using System.Web.Http;

namespace DotOPDS.Web
{
    class WebServer : IDisposable
    {
        private IDisposable server;

        public WebServer(IPEndPoint endpoint)
        {
            var owinbuilder = new AppBuilder();
            OwinServerFactory.Initialize(owinbuilder.Properties);
            new Startup().Configuration(owinbuilder);
            var builder = ServerBuilder.New()
                .SetEndPoint(endpoint)
                .SetOwinApp(owinbuilder.Build())
                .SetServerHeader("DotOPDS");

            server = builder.Start();
        }

        public void Dispose()
        {
            server.Dispose();
        }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration();

            if (Settings.Instance.Log.Level == "trace")
                config.MessageHandlers.Add(new MessageLoggingHandler());

            config.Formatters.Remove(config.Formatters.JsonFormatter);
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            var xmlFormatter = new AtomXmlMediaTypeFormatter();
            config.Formatters.Insert(0, xmlFormatter);

            config.MapHttpAttributeRoutes();

            if (Settings.Instance.Authentication.Enabled)
                appBuilder.UseBasicAuthentication();
            appBuilder.UseWebApi(config);
        }
    }
}<commit_msg>Returned JSON formatter for simpler web client code.<commit_after>﻿using DotOPDS.Middleware;
using DotOPDS.Utils;
using DotOPDS.Web.Utils;
using Microsoft.Owin.Builder;
using Newtonsoft.Json.Serialization;
using Nowin;
using Owin;
using System;
using System.Net;
using System.Web.Http;

namespace DotOPDS.Web
{
    class WebServer : IDisposable
    {
        private IDisposable server;

        public WebServer(IPEndPoint endpoint)
        {
            var owinbuilder = new AppBuilder();
            OwinServerFactory.Initialize(owinbuilder.Properties);
            new Startup().Configuration(owinbuilder);
            var builder = ServerBuilder.New()
                .SetEndPoint(endpoint)
                .SetOwinApp(owinbuilder.Build())
                .SetServerHeader("DotOPDS");

            server = builder.Start();
        }

        public void Dispose()
        {
            server.Dispose();
        }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration();

            if (Settings.Instance.Log.Level == "trace")
                config.MessageHandlers.Add(new MessageLoggingHandler());

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            var xmlFormatter = new AtomXmlMediaTypeFormatter();
            config.Formatters.Insert(0, xmlFormatter);

            config.MapHttpAttributeRoutes();

            if (Settings.Instance.Authentication.Enabled)
                appBuilder.UseBasicAuthentication();
            appBuilder.UseWebApi(config);
        }
    }
}
{'fraction_non_alphanumeric': 0.08899579073962718, 'fraction_numerical': 0.0006013229104028864, 'mean_word_length': 2.230097087378641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1834056', 'n_tokens_mistral': 870, 'n_tokens_neox': 834, 'n_words': 163}