コード例 #1
0
        public HttpWorkerRequestImpl(HttpContextBase context, HttpServerSettings settings)
            : base(context.Request.Url.LocalPath,
				TrimQuery(context.Request.Url.Query),
				null)
        {
            _context = context;
        }
コード例 #2
0
 public HttpListenerImpl(IHttpHandler app, HttpServerSettings settings)
 {
     _app = app;
     _settings = settings;
     _listener = new HttpListener();
     _listener.Prefixes.Add(string.Format(@"http://+:{0}/", settings.Port));
 }
コード例 #3
0
 public HttpListenerContextImpl(HttpListenerContext context, HttpServerSettings settings)
 {
     _context  = context;
     _settings = settings;
     _request  = new RequestImpl(context.Request);
     _response = new ResponseImpl(context.Response);
 }
コード例 #4
0
ファイル: HttpServer.cs プロジェクト: lstefano71/SharpExpress
        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();
        }
コード例 #5
0
 public HttpListenerImpl(IHttpHandler app, HttpServerSettings settings)
 {
     _app      = app;
     _settings = settings;
     _listener = new HttpListener();
     _listener.Prefixes.Add(string.Format(@"http://+:{0}/", settings.Port));
 }
コード例 #6
0
 public HttpListenerContextImpl(HttpListenerContext context, HttpServerSettings settings)
 {
     _context = context;
     _settings = settings;
     _request = new RequestImpl(context.Request);
     _response = new ResponseImpl(context.Response);
 }
コード例 #7
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);
        }
コード例 #8
0
 public HttpWorkerRequestImpl(HttpContextBase context, HttpServerSettings settings)
     : base(
         context.Request.Url.LocalPath,
         TrimQuery(context.Request.Url.Query),
         null)
 {
     _context = context;
 }
コード例 #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;
        }
コード例 #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);
 }
コード例 #11
0
ファイル: AppHost.cs プロジェクト: lstefano71/SharpExpress
        public AppHost(HttpServerSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("settings");

            _settings = settings;

            InitDomain(settings);
            InitHostingEnvironment();
        }
コード例 #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));
        }
コード例 #13
0
        public AppHost(HttpServerSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _settings = settings;

            InitDomain(settings);
            InitHostingEnvironment();
        }
コード例 #14
0
ファイル: AppHost.cs プロジェクト: lstefano71/SharpExpress
        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);
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #18
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());
                }
            }
        }
コード例 #19
0
ファイル: HttpServer.cs プロジェクト: lstefano71/SharpExpress
        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();
        }
コード例 #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);
        }
コード例 #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());
                }
            }
        }
コード例 #22
0
 public HttpContextImpl(IHttpChannel channel, HttpServerSettings settings)
 {
     ServerSettings = settings;
     _request = new HttpRequestImpl(this, channel, settings);
     _response = new HttpResponseImpl(channel);
 }
コード例 #23
0
 public HttpContextImpl(IHttpChannel channel, HttpServerSettings settings)
 {
     _request  = new HttpRequestImpl(this, channel, settings);
     _response = new HttpResponseImpl(channel);
 }