Beispiel #1
0
 public HttpRequestInfo(string ARawHTTPCommand, string ARemoteIP, string ACommand, ContextRFC AContext)
 {
     _Context      = AContext;
     _CommandType  = HttpCommandEnum.Unknown;
     _Cookies      = new ServerCookies();
     ContentLength = -1;
 }
		protected override void DoRequestNotHandled(ContextRFC AContext, HttpRequestInfo ARequestInfo, HttpResponseInfo AResponseInfo) {
			bool LHandled = false;
			if (mOnRequestNotHandled != null) {
				mOnRequestNotHandled(AContext, ARequestInfo, AResponseInfo, ref LHandled);
			}
			if (!LHandled) {
				AResponseInfo.ContentText = "<html><body><h3>The server didn't handle your request.</h3></body></html>";
			}
		}
Beispiel #3
0
 public virtual long ServeFile(ContextRFC AContext, string AFile, CustomHttpServer server)
 {
     if (ContentType.Length == 0)
     {
         ContentType = server.MimeTable.GetFileMIMEType(AFile);
     }
     ContentLength = (int)new FileInfo(AFile).Length;
     Date          = File.GetLastWriteTime(AFile);
     WriteHeader();
     AContext.TcpConnection.Socket.WriteFile(AFile);
     return(ContentLength);
 }
        protected override void DoRequestNotHandled(ContextRFC AContext, HttpRequestInfo ARequestInfo, HttpResponseInfo AResponseInfo)
        {
            bool LHandled = false;

            if (mOnRequestNotHandled != null)
            {
                mOnRequestNotHandled(AContext, ARequestInfo, AResponseInfo, ref LHandled);
            }
            if (!LHandled)
            {
                AResponseInfo.ContentText = "<html><body><h3>The server didn't handle your request.</h3></body></html>";
            }
        }
		protected override void DoCommand(ContextRFC context, HttpRequestInfo request, HttpResponseInfo response, ref bool handled) {
			switch (request.CommandType) {
				case HttpCommandEnum.Get: {
						if (mOnCommandGet != null) {
							mOnCommandGet(context, request, response, ref handled);
						}
						break;
					}
				default: {
						if (mOnCommandOther != null) {
							mOnCommandOther(context, request, response, ref handled);
						}
						break;
					}
			}
		}
Beispiel #6
0
        public virtual long SmartServeFile(ContextRFC AContext, HttpRequestInfo ARequestInfo, string AFile, CustomHttpServer server)
        {
            DateTime LFileDate = File.GetLastWriteTime(AFile);
            DateTime LReqDate  = Http.GmtToLocalDateTime(ARequestInfo.RawHeaders["If-Modified-Since"]);

            if (LReqDate.Ticks > 0 &&
                LReqDate.Subtract(new TimeSpan(LFileDate.Ticks)).Ticks < 20000)
            {
                ResponseNo = 304;
                return(0);
            }
            else
            {
                return(ServeFile(AContext, AFile, server));
            }
        }
Beispiel #7
0
		protected override void DoCommand(ContextRFC context, HttpRequestInfo request, HttpResponseInfo response, ref bool handled) {
            // first raise events is user want to handle request by event
            switch (request.CommandType)
            {
                case HttpCommandEnum.Connect:
                    if (OnCommandConnect != null) OnCommandConnect(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Delete:
                    if (OnCommandDelete != null) OnCommandDelete(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Get:
                    if (OnCommandGet != null) OnCommandGet(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Head:
                    if (OnCommandHead != null) OnCommandHead(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Options:
                    if (OnCommandOptions != null) OnCommandOptions(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Post:
                    if (OnCommandPost != null) OnCommandPost(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Put:
                    if (OnCommandPut != null) OnCommandPut(context, request, response, ref handled);
                    break;
                case HttpCommandEnum.Trace:
                    if (OnCommandTrace != null) OnCommandTrace(context, request, response, ref handled);
                    break;
                default:
                    if (OnCommandOther != null) OnCommandOther(context, request, response, ref handled);
                    break;
            }
            // if request handled from an event handler skip request handlers
            if (handled) return;

            // try to handle request by request handlers collection
            RequestHandlersLock.AcquireReaderLock(-1);
			try {
				for (int i = 0; i < mRequestHandlers.Count && !handled; i++) {
                    mRequestHandlers[i].HandleCommand(this, request, response, ref handled);
				}
			} finally {
				RequestHandlersLock.ReleaseReaderLock();
			}
		}
        protected override void DoCommand(ContextRFC context, HttpRequestInfo request, HttpResponseInfo response, ref bool handled)
        {
            switch (request.CommandType)
            {
            case HttpCommandEnum.Get: {
                if (mOnCommandGet != null)
                {
                    mOnCommandGet(context, request, response, ref handled);
                }
                break;
            }

            default: {
                if (mOnCommandOther != null)
                {
                    mOnCommandOther(context, request, response, ref handled);
                }
                break;
            }
            }
        }
		public virtual long SmartServeFile(ContextRFC AContext, HttpRequestInfo ARequestInfo, string AFile, CustomHttpServer server)
	  {
	    DateTime LFileDate = File.GetLastWriteTime(AFile);
			DateTime LReqDate = Http.GmtToLocalDateTime(ARequestInfo.RawHeaders["If-Modified-Since"]);
	    if (LReqDate.Ticks > 0
	      &&LReqDate.Subtract(new TimeSpan(LFileDate.Ticks)).Ticks < 20000)
      {
        ResponseNo = 304;
        return 0;
      }
      else
      {
          return ServeFile(AContext, AFile, server);
      }
	  }
		public virtual long ServeFile(ContextRFC AContext, string AFile, CustomHttpServer server)
	  {
	    if (ContentType.Length == 0)
	    {
            ContentType = server.MimeTable.GetFileMIMEType(AFile);
	    }
      ContentLength = (int)new FileInfo(AFile).Length;
	    Date = File.GetLastWriteTime(AFile);
	    WriteHeader();
      AContext.TcpConnection.Socket.WriteFile(AFile);
      return ContentLength;
	  }
 public HttpRequestInfo(string ARawHTTPCommand, string ARemoteIP, string ACommand, ContextRFC AContext)
 {
     _Context = AContext;
     _CommandType = HttpCommandEnum.Unknown;
     _Cookies = new ServerCookies();
     ContentLength = -1;
 }
Beispiel #12
0
        protected override void DoCommand(ContextRFC context, HttpRequestInfo request, HttpResponseInfo response, ref bool handled)
        {
            // first raise events is user want to handle request by event
            switch (request.CommandType)
            {
            case HttpCommandEnum.Connect:
                if (OnCommandConnect != null)
                {
                    OnCommandConnect(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Delete:
                if (OnCommandDelete != null)
                {
                    OnCommandDelete(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Get:
                if (OnCommandGet != null)
                {
                    OnCommandGet(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Head:
                if (OnCommandHead != null)
                {
                    OnCommandHead(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Options:
                if (OnCommandOptions != null)
                {
                    OnCommandOptions(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Post:
                if (OnCommandPost != null)
                {
                    OnCommandPost(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Put:
                if (OnCommandPut != null)
                {
                    OnCommandPut(context, request, response, ref handled);
                }
                break;

            case HttpCommandEnum.Trace:
                if (OnCommandTrace != null)
                {
                    OnCommandTrace(context, request, response, ref handled);
                }
                break;

            default:
                if (OnCommandOther != null)
                {
                    OnCommandOther(context, request, response, ref handled);
                }
                break;
            }
            // if request handled from an event handler skip request handlers
            if (handled)
            {
                return;
            }

            // try to handle request by request handlers collection
            RequestHandlersLock.AcquireReaderLock(-1);
            try {
                for (int i = 0; i < mRequestHandlers.Count && !handled; i++)
                {
                    mRequestHandlers[i].HandleCommand(this, request, response, ref handled);
                }
            } finally {
                RequestHandlersLock.ReleaseReaderLock();
            }
        }