コード例 #1
0
 public void AddContext(PodeContext context)
 {
     lock (Contexts)
     {
         Contexts.Add(context);
     }
 }
コード例 #2
0
        public PodeListener(CancellationToken cancellationToken, PodeListenerType type = PodeListenerType.Http)
        {
            CancellationToken = cancellationToken;
            IsDisposed        = false;
            Type = type;

            WebBuilder = new WebHostBuilder();
            WebBuilder.ConfigureServices(s => s.AddRouting());
            WebBuilder.Configure(app => {
                var routeHandler = new RouteHandler(ctx => {
                    var _podeContext = new PodeContext(ctx, this);
                    this.AddContext(_podeContext);
                    return(_podeContext.Start());
                });

                var routeBuilder = new RouteBuilder(app, routeHandler);
                routeBuilder.MapRoute("pode sub-routes", "{*.}");

                var routes = routeBuilder.Build();
                app.UseRouter(routes);
            });

            Sockets  = new List <PodeSocket>();
            Contexts = new BlockingCollection <PodeContext>();
        }
コード例 #3
0
        public PodeRequest(HttpRequest request, PodeContext context)
        {
            Request = request;
            Context = context;

            var _proto = (Request.IsHttps ? "https" : "http");

            Url = new Uri($"{_proto}://{Host}{Request.Path.Value}");

            RemoteEndpoint = new IPEndPoint(Request.HttpContext.Connection.RemoteIpAddress, Request.HttpContext.Connection.RemotePort);
            LocalEndpoint  = new IPEndPoint(Request.HttpContext.Connection.LocalIpAddress, Request.HttpContext.Connection.LocalPort);

            QueryString = new NameValueCollection();
            foreach (var key in Request.Query.Keys)
            {
                QueryString.Add(key, Request.Query[key]);
            }

            Headers = new Hashtable();
            foreach (var key in Request.Headers.Keys)
            {
                Headers.Add(key, Request.Headers[key]);
            }

            Error = default(HttpRequestException);
        }
コード例 #4
0
        public PodeRequest(HttpRequest request, PodeContext context)
        {
            Request = request;
            Context = context;

            // default values
            HttpMethod      = Request.Method;
            Host            = Request.Host.Value;
            ContentType     = Request.ContentType;
            ContentLength   = Request.ContentLength.HasValue ? Request.ContentLength.Value : 0;
            Protocol        = Request.Scheme;
            ProtocolVersion = (Request.Protocol.Split('/')[1]);
            UserAgent       = Request.Headers.ContainsKey("User-Agent") ? (string)Request.Headers["User-Agent"] : string.Empty;
            UrlReferrer     = Request.Headers.ContainsKey("Referer") ? (string)Request.Headers["Referer"] : string.Empty;

            // protocol and url
            var _proto = (Request.IsHttps ? "https" : "http");

            Url = new Uri($"{_proto}://{Host}{Request.Path.Value}");

            RemoteEndpoint = new IPEndPoint(Request.HttpContext.Connection.RemoteIpAddress, Request.HttpContext.Connection.RemotePort);
            LocalEndpoint  = new IPEndPoint(Request.HttpContext.Connection.LocalIpAddress, Request.HttpContext.Connection.LocalPort);

            // query string
            QueryString = new NameValueCollection();
            foreach (var key in Request.Query.Keys)
            {
                QueryString.Add(key, Request.Query[key]);
            }

            // headers
            Headers = new Hashtable();
            foreach (var key in Request.Headers.Keys)
            {
                Headers.Add(key, Request.Headers[key]);
            }

            // reset error
            Error = default(HttpRequestException);
        }