Inheritance: HttpIncomingRequestResponse
Exemplo n.º 1
0
        protected override void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
        {
            base.HandleHttpRequest(connection, request, response);

            if (response.ContentSource == ContentSource.ContentNone)
            {
                if (request.Header.RequestType == "GET")
                {
                    String lPath = RootPath + request.Header.RequestPath.Replace('/', Path.DirectorySeparatorChar);
                    if (lPath.IndexOf("..") == -1)
                    {
                        if (File.Exists(lPath))
                        {
                            response.Header.ContentType = "text/html";
                            response.ContentStream      = new FileStream(lPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                            response.CloseStream        = true; /* Response will close stream once it's been sent */
                        }
                        else
                        {
                            response.SendError(HttpStatusCode.NotFound, String.Format("File '{0}' not found.", lPath));
                        }
                    }
                    else
                    {
                        response.SendError(HttpStatusCode.Forbidden, String.Format("Bad Request: Path '{0}' contains '..' which is invalid.", lPath));
                    }
                }
                else
                {
                    response.SendError(HttpStatusCode.BadRequest, String.Format("Request Type '{0}' not supported.", request.Header.RequestType));
                }
            }
        }
 public HttpRequestEventArgs(Connection connection, HttpServerRequest request, HttpServerResponse response)
     : base(connection)
 {
     this.fRequest  = request;
     this.fResponse = response;
     this.Handled   = false;
 }
Exemplo n.º 3
0
        protected internal override void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
        {
            base.HandleHttpRequest(connection, request, response);

            if (response.ContentSource == ContentSource.ContentNone)
            {
                if (request.Header.RequestType == "GET")
                {
                    String lPath = RootPath + request.Header.RequestPath.Replace('/', Path.DirectorySeparatorChar);
                    if (lPath.IndexOf("..") == -1)
                    {
                        if (File.Exists(lPath))
                        {
                            response.Header.ContentType = "text/html";
                            response.ContentStream = new FileStream(lPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                            response.CloseStream = true; /* Response will close stream once it's been sent */
                        }
                        else
                        {
                            response.SendError(404, String.Format("File '{0}' not found.", lPath));
                        }
                    }
                    else
                    {
                        response.SendError(403, String.Format("Bad Request: Path '{0}' contains '..' which is invalid.", lPath));
                    }
                }
                else
                {
                    response.SendError(500, String.Format("Request Type '{0}' not supported.", request.Header.RequestType));
                }
            }
        }
Exemplo n.º 4
0
		protected override void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
		{
			base.HandleHttpRequest(connection, request, response);

			if (response.ContentSource != ContentSource.ContentNone)
			{
				return;
			}

			if (request.Header.RequestType != "GET")
			{
				response.SendError(HttpStatusCode.BadRequest, String.Format("Request Type '{0}' not supported.", request.Header.RequestType));
				return;
			}

			String lPath = RootPath + request.Header.RequestPath.Replace('/', Path.DirectorySeparatorChar);
			if (lPath.IndexOf("..", StringComparison.Ordinal) != -1)
			{
				response.SendError(HttpStatusCode.Forbidden, String.Format("Bad Request: Path '{0}' contains '..' which is invalid.", lPath));
				return;
			}

			if (!File.Exists(lPath))
			{
				response.SendError(HttpStatusCode.NotFound, String.Format("File '{0}' not found.", lPath));
				return;
			}

			response.Header.ContentType = "text/html";
			response.ContentStream = new FileStream(lPath, FileMode.Open, FileAccess.Read, FileShare.Read);
			response.CloseStream = true; /* Response will close stream once it's been sent */
		}
Exemplo n.º 5
0
 protected virtual void TriggerOnHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
 {
     if (OnHttpRequest != null)
     {
         OnHttpRequestArgs lEventArgs = new OnHttpRequestArgs(connection, request, response);
         OnHttpRequest(this, lEventArgs);
     }
 }
Exemplo n.º 6
0
            public virtual void ProcessRequests()
            {
                do
                {
                    try
                    {
                        HttpHeaders lHeaders = HttpHeaders.Create(DataConnection);
                        if (lHeaders == null)
                        {
                            DataConnection.Close();                             // disconnected
                            break;
                        }
                        HttpServerRequest lRequest = new HttpServerRequest(DataConnection, lHeaders);

                        /* ToDo: make (some) validation optinal, for speed purposes */
                        if (Owner.ValidateRequests)
                        {
                            lRequest.Validate();
                        }

                        HttpServerResponse lResponse = new HttpServerResponse();
                        lResponse.KeepAlive = (lRequest.KeepAlive && Owner.KeepAlive);
                        lResponse.Header.SetHeaderValue("Server", Owner.ServerName);

                        this.Owner.HandleHttpRequest(DataConnection, lRequest, lResponse);

                        lRequest.FlushContent();

                        lResponse.WriteToConnection(DataConnection);
                        if (!lRequest.KeepAlive || !Owner.KeepAlive)
                        {
                            DataConnection.Close(false);
                        }
                    }
                    catch (HttpRequestInvalidException e)
                    {
                        this.SendError(e.ErrorCode, e);
                    }
                    catch (ConnectionClosedException)
                    {
                        DataConnection.Close(false);
                    }
                    catch (SocketException)
                    {
                        DataConnection.Close(false);
                    }
                    catch (Exception e)
                    {
                        this.SendError(HttpStatusCode.InternalServerError, e);
                    }
                }while (this.DataConnection.Connected);

                DataConnection.Close();
            }
Exemplo n.º 7
0
 protected virtual void TriggerOnHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
 {
     if (OnHttpRequest != null)
     {
         OnHttpRequestArgs lEventArgs = new OnHttpRequestArgs(connection, request, response);
         OnHttpRequest(this, lEventArgs);
     }
 }
Exemplo n.º 8
0
 public OnHttpRequestArgs(Connection connection, HttpServerRequest request, HttpServerResponse response)
     : base(connection)
 {
     this.fRequest = request;
     this.fResponse = response;
 }
Exemplo n.º 9
0
        public virtual void ProcessRequests()
        {
            do
            {
                try
                {
                    HttpHeaders lHeaders = HttpHeaders.Create(DataConnection);
                    if (lHeaders == null)
                    {
                        DataConnection.Close(); // disconnected
                        break;
                    }
                    HttpServerRequest lRequest = new HttpServerRequest(DataConnection, lHeaders);

                    /* ToDo: make (some) validation optinal, for speed purposes */
                    if (Owner.ValidateRequests)
                        lRequest.Validate();

                    HttpServerResponse lResponse = new HttpServerResponse();
                    lResponse.KeepAlive = (lRequest.KeepAlive && Owner.KeepAlive);
                    lResponse.Header.SetHeaderValue("Server", Owner.ServerName);

                    Owner.HandleHttpRequest(DataConnection, lRequest, lResponse);

                    lRequest.FlushContent();

                    lResponse.WriteToConnection(DataConnection);
                    if (!lRequest.KeepAlive)
                        DataConnection.Close(false);
                }
                catch (HttpRequestInvalidException e)
                {
                    e.Response.Header.SetHeaderValue("Server", Owner.ServerName);
                    e.Response.WriteToConnection(DataConnection);
                    DataConnection.Close();
                }
                catch (ConnectionClosedException)
                {
                    DataConnection.Close(false);
                }
                catch (SocketException)
                {
                    DataConnection.Close(false);
                }
                catch (Exception e)
                {
                    HttpServerResponse lResponse = new HttpServerResponse();
                    lResponse.Header.SetHeaderValue("Server", Owner.ServerName);
                    lResponse.SendError(500, "Server Error while processing HTTP request.", e);
                    lResponse.WriteToConnection(DataConnection);
                    DataConnection.Close();
                }

                if (!Owner.KeepAlive)
                    DataConnection.Close();
            }
            while (Owner.KeepAlive && DataConnection.Connected);
        }
Exemplo n.º 10
0
 internal protected virtual void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
 {
     this.TriggerOnHttpRequest(connection, request, response);
 }
Exemplo n.º 11
0
 public OnHttpRequestArgs(Connection connection, HttpServerRequest request, HttpServerResponse response)
     : base(connection)
 {
     this.fRequest  = request;
     this.fResponse = response;
 }
Exemplo n.º 12
0
 internal protected virtual void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
 {
     this.TriggerOnHttpRequest(connection, request, response);
 }
Exemplo n.º 13
0
 protected virtual void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
 {
     this.TriggerHttpRequest(new HttpRequestEventArgs(connection, request, response));
 }
Exemplo n.º 14
0
			private void ProcessRequests()
			{
				do
				{
					try
					{
						HttpHeaders lHeaders = HttpHeaders.Create(DataConnection);
						if (lHeaders == null)
						{
							DataConnection.Close(); // disconnected
							break;
						}
						HttpServerRequest lRequest = new HttpServerRequest(DataConnection, lHeaders);

						if (Owner.ValidateRequests)
							lRequest.Validate();

						HttpServerResponse lResponse = new HttpServerResponse();
						lResponse.KeepAlive = (lRequest.KeepAlive && Owner.KeepAlive);
						lResponse.Header.SetHeaderValue("Server", Owner.ServerName);

						this.Owner.HandleHttpRequest(DataConnection, lRequest, lResponse);

						lRequest.FlushContent();

						lResponse.WriteToConnection(DataConnection);
						if (!lRequest.KeepAlive || !this.Owner.KeepAlive)
							this.DataConnection.Close();
					}
					catch (HttpRequestInvalidException e)
					{
						this.SendError(e.ErrorCode, e);
					}
					catch (ConnectionClosedException)
					{
						this.DataConnection.Close();
					}
					catch (SocketException)
					{
						this.DataConnection.Close();
					}
					catch (Exception e)
					{
						this.SendError(HttpStatusCode.InternalServerError, e);
					}
				}
				while (this.DataConnection.Connected);

				this.DataConnection.Close();
			}
Exemplo n.º 15
0
		protected virtual void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
		{
			this.TriggerHttpRequest(new HttpRequestEventArgs(connection, request, response));
		}