コード例 #1
0
        //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;
            }
        }
コード例 #2
0
ファイル: HttpWebServer.cs プロジェクト: GotenXiao/blink1
		//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;
			}
		}
コード例 #3
0
ファイル: HttpServer.cs プロジェクト: GotenXiao/blink1
		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
			{
			}
		}