public HttpWorkerRequestImpl(HttpContextBase context, HttpServerSettings settings)
            : base(context.Request.Url.LocalPath,
				TrimQuery(context.Request.Url.Query),
				null)
        {
            _context = context;
        }
Ejemplo n.º 2
0
 public HttpListenerImpl(IHttpHandler app, HttpServerSettings settings)
 {
     _app = app;
     _settings = settings;
     _listener = new HttpListener();
     _listener.Prefixes.Add(string.Format(@"http://+:{0}/", settings.Port));
 }
 public HttpListenerContextImpl(HttpListenerContext context, HttpServerSettings settings)
 {
     _context  = context;
     _settings = settings;
     _request  = new RequestImpl(context.Request);
     _response = new ResponseImpl(context.Response);
 }
Ejemplo n.º 4
0
        public HttpServer(IHttpHandler app, HttpServerSettings settings)
        {
            if (app == null) throw new ArgumentNullException("app");
            if (settings == null) throw new ArgumentNullException("settings");

            // init asp.net host
            if (settings.AspNetHost)
            {
                var appHost = new AppHost(settings);
                appHost.Init();
            }

            IHttpListener listener;

            switch (settings.Mode)
            {
                case HttpServerMode.TcpListener:
                    listener = new TcpListenerImpl(app, settings);
                    break;
                case HttpServerMode.HttpListener:
                    listener = new HttpListenerImpl(app, settings);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            _listener = listener;
            _listener.Start();

            _listenerThread = new Thread(Listen);
            _listenerThread.Start();
        }
Ejemplo n.º 5
0
 public HttpListenerImpl(IHttpHandler app, HttpServerSettings settings)
 {
     _app      = app;
     _settings = settings;
     _listener = new HttpListener();
     _listener.Prefixes.Add(string.Format(@"http://+:{0}/", settings.Port));
 }
 public HttpListenerContextImpl(HttpListenerContext context, HttpServerSettings settings)
 {
     _context = context;
     _settings = settings;
     _request = new RequestImpl(context.Request);
     _response = new ResponseImpl(context.Response);
 }
        public HttpWorkerRequestImpl(HttpListenerContext context, HttpServerSettings settings)
            : base(context.Request.Url.LocalPath,
				TrimQuery(context.Request.Url.Query),
				null)
        {
            _listenerContext = context;
            _context = new HttpListenerContextImpl(context, settings);
        }
Ejemplo n.º 8
0
 public HttpWorkerRequestImpl(HttpContextBase context, HttpServerSettings settings)
     : base(
         context.Request.Url.LocalPath,
         TrimQuery(context.Request.Url.Query),
         null)
 {
     _context = context;
 }
Ejemplo n.º 9
0
        public HttpWorkerRequestImpl(HttpContextBase context, HttpServerSettings settings)
            : base(context.Request.Url.LocalPath,
				TrimQuery(context.Request.Url.Query),
				null)
        {
            _context = context;
            _url = context.Request.Url.ToString();
            _localPort = settings.Port;
        }
Ejemplo n.º 10
0
 public HttpWorkerRequestImpl(HttpListenerContext context, HttpServerSettings settings)
     : base(
         context.Request.Url.LocalPath,
         TrimQuery(context.Request.Url.Query),
         null)
 {
     _listenerContext = context;
     _context         = new HttpListenerContextImpl(context, settings);
 }
Ejemplo n.º 11
0
        public AppHost(HttpServerSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("settings");

            _settings = settings;

            InitDomain(settings);
            InitHostingEnvironment();
        }
Ejemplo n.º 12
0
        public TcpListenerImpl(IHttpHandler handler, HttpServerSettings settings)
        {
            if (handler == null) throw new ArgumentNullException("handler");
            if (settings == null) throw new ArgumentNullException("settings");

            _handler = handler;
            _settings = settings;

            // TODO endpoint setting
            _listener = new TcpListener(new IPEndPoint(IPAddress.Loopback, settings.Port));
        }
Ejemplo n.º 13
0
        public AppHost(HttpServerSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _settings = settings;

            InitDomain(settings);
            InitHostingEnvironment();
        }
Ejemplo n.º 14
0
        public static void InitDomain(HttpServerSettings settings)
        {
            var uniqueAppString = string.Format(
                    CultureInfo.InvariantCulture, "{0}{1}:{2}",
                    settings.VirtualDir, settings.PhisycalDir, settings.Port)
                    .ToLowerInvariant();
            var appId = (uniqueAppString.GetHashCode()).ToString("x", CultureInfo.InvariantCulture);

            var domain = Thread.GetDomain();
            domain.SetData(".appDomain", "express-domain");
            domain.SetData(".appId", appId);
            domain.SetData(".appPath", settings.PhisycalDir);
            domain.SetData(".appVPath", settings.VirtualDir);
            domain.SetData(".domainId", appId);
        }
Ejemplo n.º 15
0
        public static void InitDomain(HttpServerSettings settings)
        {
            var uniqueAppString = string.Format(
                CultureInfo.InvariantCulture, "{0}{1}:{2}",
                settings.VirtualDir, settings.PhisycalDir, settings.Port)
                                  .ToLowerInvariant();
            var appId = (uniqueAppString.GetHashCode()).ToString("x", CultureInfo.InvariantCulture);

            var domain = Thread.GetDomain();

            domain.SetData(".appDomain", "express-domain");
            domain.SetData(".appId", appId);
            domain.SetData(".appPath", settings.PhisycalDir);
            domain.SetData(".appVPath", settings.VirtualDir);
            domain.SetData(".domainId", appId);
        }
Ejemplo n.º 16
0
        public TcpListenerImpl(IHttpHandler handler, HttpServerSettings settings)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _handler  = handler;
            _settings = settings;

            // TODO endpoint setting
            _listener = new TcpListener(new IPEndPoint(IPAddress.Loopback, settings.Port));
        }
Ejemplo n.º 17
0
        public HttpRequestImpl(HttpContextImpl context, IHttpChannel channel, HttpServerSettings settings)
        {
            _context = context;

            Method = channel.Method;

            var path = channel.Path;
            if (!path.StartsWith("/")) path = "/" + path;
            Uri = new Uri(string.Format("http://localhost:{0}{1}", settings.Port, path));

            _headers.AddRange(
                from key in channel.Headers.AllKeys
                select new KeyValuePair<string, string>(key, channel.Headers[key])
                );

            var len = _headers.GetContentLength();
            Body = len > 0 ? channel.Body : new MemoryStream(new byte[0], false);
        }
        public static void ProcessRequest(this IHttpChannel channel, IHttpHandler handler, HttpServerSettings settings)
        {
            var context = new HttpContextImpl(channel, settings);
            var res = context.Response;

            using (res.OutputStream)
            {
                try
                {
                    var app = handler as ExpressApplication;
                    if (app != null)
                    {
                        if (!app.Process(context))
                        {
                            res.StatusCode = (int)HttpStatusCode.NotFound;
                            res.StatusDescription = "Not found";
                            res.ContentType = "text/plain";
                            res.Write("Resource not found!");
                        }

                        res.Flush();
                        res.End();
                    }
                    else
                    {
                        var workerRequest = new HttpWorkerRequestImpl(context, settings);
                        handler.ProcessRequest(new HttpContext(workerRequest));
                        workerRequest.EndOfRequest();
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e);

                    res.StatusCode = (int)HttpStatusCode.InternalServerError;
                    res.ContentType = "text/plain";
                    res.Write(e.ToString());
                }
            }
        }
Ejemplo n.º 19
0
        public HttpServer(IHttpHandler app, HttpServerSettings settings)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            // init asp.net host
            if (settings.AspNetHost)
            {
                var appHost = new AppHost(settings);
                appHost.Init();
            }

            IHttpListener listener;

            switch (settings.Mode)
            {
            case HttpServerMode.TcpListener:
                listener = new TcpListenerImpl(app, settings);
                break;

            case HttpServerMode.HttpListener:
                listener = new HttpListenerImpl(app, settings);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            _listener = listener;
            _listener.Start();

            _listenerThread = new Thread(Listen);
            _listenerThread.Start();
        }
Ejemplo n.º 20
0
        public HttpRequestImpl(HttpContextImpl context, IHttpChannel channel, HttpServerSettings settings)
        {
            _context = context;

            Method = channel.Method;

            var path = channel.Path;

            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }
            Uri = new Uri(string.Format("http://localhost:{0}{1}", settings.Port, path));

            _headers.AddRange(
                from key in channel.Headers.AllKeys
                select new KeyValuePair <string, string>(key, channel.Headers[key])
                );

            var len = _headers.GetContentLength();

            Body = len > 0 ? channel.Body : new MemoryStream(new byte[0], false);
        }
Ejemplo n.º 21
0
        public static void ProcessRequest(this IHttpChannel channel, IHttpHandler handler, HttpServerSettings settings)
        {
            var context = new HttpContextImpl(channel, settings);
            var res     = context.Response;

            using (res.OutputStream)
            {
                try
                {
                    var app = handler as ExpressApplication;
                    if (app != null)
                    {
                        if (!app.Process(context))
                        {
                            res.StatusCode        = (int)HttpStatusCode.NotFound;
                            res.StatusDescription = "Not found";
                            res.ContentType       = "text/plain";
                            res.Write("Resource not found!");
                        }

                        res.Flush();
                        res.End();
                    }
                    else
                    {
                        var workerRequest = new HttpWorkerRequestImpl(context, settings);
                        handler.ProcessRequest(new HttpContext(workerRequest));
                        workerRequest.EndOfRequest();
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e);

                    res.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    res.ContentType = "text/plain";
                    res.Write(e.ToString());
                }
            }
        }
Ejemplo n.º 22
0
 public HttpContextImpl(IHttpChannel channel, HttpServerSettings settings)
 {
     ServerSettings = settings;
     _request = new HttpRequestImpl(this, channel, settings);
     _response = new HttpResponseImpl(channel);
 }
Ejemplo n.º 23
0
 public HttpContextImpl(IHttpChannel channel, HttpServerSettings settings)
 {
     _request  = new HttpRequestImpl(this, channel, settings);
     _response = new HttpResponseImpl(channel);
 }