Beispiel #1
0
        internal void OnRequestReceived(HttpClient client, HttpRequest request)
        {
            try
            {
                RequestEventArgs args = new RequestEventArgs(client, request);

                if (RequestReceived != null)
                {
                    RequestReceived(this, args);
                }
                if (request.IsValidRequest)
                {
                    if (logRequests)
                    {
                        //BUG: Uri.ToString() decodes a url encoded string for a second time; % disappears
                        Log.WriteLine("Request: " + client.RemoteAddress + " " + request.Uri);
                    }
                    if (ValidRequestReceived != null)
                    {
                        ValidRequestReceived(this, args);
                    }
                }
                else
                {
                    if (InvalidRequestReceived != null)
                    {
                        InvalidRequestReceived(this, args);
                    }
                }
            }
            finally
            {
            }
        }
Beispiel #2
0
 /// <summary>
 /// This intercepts a request to the server and acts as an HTTP filter.
 /// If the uri contains the string '/addins/images/' it is an image comming from the addin assembly.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 static void httpServer_RequestReceived(object sender, RequestEventArgs e)
 {
     string uri = e.Request.Uri.ToString();
     if (uri.ToLower().IndexOf("/addins/") > 0)
     {
         try
         {
             string rest = uri.Substring(uri.ToLower().IndexOf("/addins/") + 8);
                                            
             string addinname = rest.Substring(0, rest.IndexOf("/"));
             string document = rest.Substring(rest.IndexOf("/"));
             int index = Application.Addins.FindAddinIndex(addinname);
             Stream stream = null;
             if (index >= 0)
             {
                 stream = Application.Addins.Extensions[index].GetDocument(document);
                 if (stream == null)
                     e.Request.Response.ResponseCode = "404";                            
                 else
                     e.Request.Response.ResponseContent = stream;
             }
             else
                 return;
         }
         catch { }
     }
     // Trace.WriteLine(e.Request.Uri.ToString());
     
 }
		//TODO: a system for IFile and IDirectory handler extensibility

		private void server_ValidRequestReceived(object sender, RequestEventArgs e)
		{

			if(e.Request.Uri.AbsolutePath.IndexOfAny(new char[] {'*', '?'}) >= 0)
			{
				throw new HttpRequestException("401");
			}

			IResource resource;

			try
			{
				resource = NavigateToUrl(e.Request.Uri.AbsolutePath, true);

				SendFileOrIndex(e.Request, resource);
			}
			catch(MovedException ex)
			{
				if(this.LogRequests)
					Log.WriteLine("Redirect: {0} to {1}", e.Request.Uri.AbsoluteUri, ex.NewPath);
				e.Request.Response.SetHeader("Location", ex.NewPath);
				throw;
			}
		}
Beispiel #4
0
		internal void OnRequestReceived(HttpClient client, HttpRequest request)
		{
			try
			{
				RequestEventArgs args = new RequestEventArgs(client, request);

				if(RequestReceived != null)
					RequestReceived(this, args);
				if(request.IsValidRequest)
				{
					if(logRequests)
						//BUG: Uri.ToString() decodes a url encoded string for a second time; % disappears
						Log.WriteLine("Request: " + client.RemoteAddress + " " + request.Uri);
					if(ValidRequestReceived != null)
						ValidRequestReceived(this, args);
				}
				else
				{
					if(InvalidRequestReceived != null)
						InvalidRequestReceived(this, args);
				}
			}
			finally
			{
			}
		}