Ejemplo n.º 1
0
 public static IPAddress GetClientIp(HttpListenerContext httpContext, HashSet <IPAddress> trustedProxies = null)
 {
     return(GetClientIp(httpContext.Request.RemoteEndPoint?.Address,
                        httpContext.Request.Headers["X-Forwarded-For"]?.Split(','),
                        httpContext.Request.Headers["X-Real-IP"],
                        trustedProxies));
 }
 internal HttpListenerRequest(WebSocketSharp.Net.HttpListenerContext context)
 {
     this._context       = context;
     this._contentLength = (long)-1;
     this._headers       = new WebSocketSharp.Net.WebHeaderCollection();
     this._identifier    = Guid.NewGuid();
 }
Ejemplo n.º 3
0
        /*
         * Handles a new request.
         */
        public void HandleRequest(HttpListenerContext httpRequestContext)
        {
            // Create and start the handler.
            var handler = new ContextHandler(httpRequestContext, this.Handlers);

            handler.StartHandling();
        }
Ejemplo n.º 4
0
 internal HttpListenerResponse(WebSocketSharp.Net.HttpListenerContext context)
 {
     this._context           = context;
     this._keepAlive         = true;
     this._statusCode        = 200;
     this._statusDescription = "OK";
     this._version           = WebSocketSharp.Net.HttpVersion.Version11;
 }
Ejemplo n.º 5
0
        internal static WsStream CreateServerStream(WebSocketSharp.Net.HttpListenerContext context)
        {
            var conn   = context.Connection;
            var stream = conn.Stream;

            return(conn.IsSecure
                   ? new WsStream((SslStream)stream)
                   : new WsStream((NetworkStream)stream));
        }
Ejemplo n.º 6
0
 private void init()
 {
     this._context       = new WebSocketSharp.Net.HttpListenerContext(this);
     this._inputState    = InputState.RequestLine;
     this._inputStream   = null;
     this._lineState     = LineState.None;
     this._outputStream  = null;
     this._position      = 0;
     this._requestBuffer = new MemoryStream();
 }
        public WebServerRequestContext(HttpListenerContext httpContext, IPAddress remoteEndpoint)
        {
            this.httpContext = httpContext;

            QueryString = QueryStringValuesCollection.FromNameValueCollection(httpContext.Request.QueryString);
            Headers     = QueryStringValuesCollection.FromNameValueCollection(httpContext.Request.Headers);

            RemoteEndpoint = remoteEndpoint;
            ForwardedUri   = Headers.GetStringOrDefault("X-Forwarded-Uri", null);

            HttpMethod = new HttpMethod(httpContext.Request.HttpMethod);
        }
Ejemplo n.º 8
0
        private async Task InternalRun()
        {
            while (true)
            {
                HttpListenerContext httpContext = null;
                try {
                    httpContext = await Task.Factory.FromAsync(_listener.BeginGetContext, _listener.EndGetContext, null);

                    var handler = new WebServerClientHandler(this, httpContext);
                    handler.Handle();
                }
                catch (Exception e) {
                    _logger.Error(e, "An error occurred during handling webserver client");
                    if (httpContext != null)
                    {
                        httpContext.Response.StatusCode = 500;
                        httpContext.Response.Close();
                    }
                }
            }
        }