Пример #1
0
        private void Init()
        {
            _sessionStore = _components.Get <IHttpSessionStore>();
            if (_sessionStore == null)
            {
                WriteLog(this, LogPrio.Info, "Defaulting to memory session store.");
                _sessionStore = new MemorySessionStore();
            }

            // add default decoders if none have been added.
            if (FormDecoderProviders.Count == 0)
            {
                WriteLog(
                    this, LogPrio.Info,
                    "Loading UrlDecoder, XmlDecoder and MultipartDecoder, since no decoders have been added.");
                _formDecodersProvider.Add(new UrlDecoder());
                _formDecodersProvider.Add(new MultipartDecoder());
                _formDecodersProvider.Add(new XmlDecoder());
            }

            // Components for building requests.
            if (!_components.Contains(typeof(IRequestParserFactory)))
            {
                _components.Add <IRequestParserFactory, RequestParserFactory>();
            }
            if (!_components.Contains(typeof(IHttpContextFactory)))
            {
                _components.AddInstance <IHttpContextFactory>(
                    new HttpContextFactory(
                        LogWriter, 16384,
                        _components.Get
                        <IRequestParserFactory>()));
            }

            // the special folder does not exist on mono
            string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);

            if (string.IsNullOrEmpty(tempPath))
            {
                tempPath = "/var/tmp/";
            }
            if (!Directory.Exists(tempPath))
            {
                WriteLog(this, LogPrio.Warning, "Temp path do not exist: " + tempPath);
                return;
            }
            DirectoryInfo info = new DirectoryInfo(tempPath);

            foreach (FileInfo file in info.GetFiles("*.tmp"))
            {
                file.Delete();
            }

            _requestQueue.Start();
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpServer"/> class.
 /// </summary>
 /// <param name="decoderProvider">Form decoders are used to convert different types of posted data to the <see cref="HttpInput"/> object types.</param>
 /// <param name="logWriter">The log writer.</param>
 /// <seealso cref="IFormDecoder"/>
 /// <seealso cref="FormDecoderProviders"/>
 /// <seealso cref="LogWriter"/>
 public HttpServer(FormDecoderProvider decoderProvider, ILogWriter logWriter)
 {
     Check.Require(decoderProvider, "decoderProvider");
     _components = new ComponentProvider();
     _components.AddInstance <FormDecoderProvider>(decoderProvider);
     if (logWriter != null)
     {
         _components.AddInstance <ILogWriter>(logWriter);
         _logWriter = logWriter;
     }
     _components.Get <ILogWriter>();
     _requestQueue = new RequestQueue(ProcessRequestWrapper);
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpServer"/> class.
 /// </summary>
 /// <param name="decoderProvider">Form decoders are used to convert different types of posted data to the <see cref="HttpInput"/> object types.</param>
 /// <param name="logWriter">The log writer.</param>
 /// <seealso cref="IFormDecoder"/>
 /// <seealso cref="FormDecoderProviders"/>
 /// <seealso cref="LogWriter"/>
 public HttpServer(FormDecoderProvider decoderProvider, ILogWriter logWriter)
 {
     Check.Require(decoderProvider, "decoderProvider");
     _components = new ComponentProvider();
     _components.AddInstance<FormDecoderProvider>(decoderProvider);
     if (logWriter != null)
     {
         _components.AddInstance<ILogWriter>(logWriter);
         _logWriter = logWriter;
     }
     _components.Get<ILogWriter>();
     _requestQueue = new RequestQueue(ProcessRequestWrapper);
 }