Пример #1
0
        public void Run(object state)
        {
            int requestId           = -1;
            XSPRequestBroker broker = null;

            try {
                if (remoteEP == null)
                {
                    return;
                }

                InitialWorkerRequest ir = new InitialWorkerRequest(stream);
                try {
                    ir.ReadRequestData();
                } catch (Exception ex) {
                    if (ir.GotSomeInput)
                    {
                        byte [] badReq = HttpErrors.BadRequest();
                        Write(badReq, 0, badReq.Length);
                    }

                    throw ex;
                }

                RequestData rdata = ir.RequestData;
                string      vhost = null;            // TODO: read the headers in InitialWorkerRequest
                int         port  = ((IPEndPoint)localEP).Port;

                VPathToHost        vapp = server.GetApplicationForPath(vhost, port, rdata.Path, true);
                XSPApplicationHost host = null;
                if (vapp != null)
                {
                    host = (XSPApplicationHost)vapp.AppHost;
                }

                if (host == null)
                {
                    byte [] nf = HttpErrors.NotFound(rdata.Path);
                    Write(nf, 0, nf.Length);
                    Close();
                    return;
                }

                broker    = (XSPRequestBroker)vapp.RequestBroker;
                requestId = broker.RegisterRequest(this);

                string redirect;
                vapp.Redirect(rdata.Path, out redirect);
                host.ProcessRequest(requestId, localEP.Address.Address, localEP.Port,
                                    remoteEP.Address.Address, remoteEP.Port, rdata.Verb,
                                    rdata.Path, rdata.QueryString,
                                    rdata.Protocol, rdata.InputBuffer, redirect);
            } catch (Exception e) {
                bool ignore = ((e is RequestLineException) || (e is IOException));
                if (!ignore)
                {
                    Console.WriteLine(e);
                }

                try {
                    if (!ignore)
                    {
                        byte [] error = HttpErrors.ServerError();
                        Write(error, 0, error.Length);
                    }
                } catch {}
                try {
                    Close();
                } catch {}

                if (broker != null && requestId != -1)
                {
                    broker.UnregisterRequest(requestId);
                }
            }
        }
Пример #2
0
		public void Run (object state)
		{
			int requestId = -1;
			XSPRequestBroker broker = null;
			
			try {
				if (remoteEP == null)
					return;

				InitialWorkerRequest ir = new InitialWorkerRequest (stream);
				try {
					ir.ReadRequestData ();
				} catch (Exception ex) {
					if (ir.GotSomeInput) {
						byte [] badReq = HttpErrors.BadRequest ();
						Write (badReq, 0, badReq.Length);
					}

					throw ex;
				}

				RequestData rdata = ir.RequestData;
				string vhost = null; // TODO: read the headers in InitialWorkerRequest
				int port = ((IPEndPoint) localEP).Port;
				
				VPathToHost vapp = server.GetApplicationForPath (vhost, port, rdata.Path, true);
				XSPApplicationHost host = null;
				if (vapp != null)
					host = (XSPApplicationHost) vapp.AppHost;

				if (host == null) {
					byte [] nf = HttpErrors.NotFound (rdata.Path);
					Write (nf, 0, nf.Length);
					Close ();
					return;
				}
				
				broker = (XSPRequestBroker) vapp.RequestBroker;
				requestId = broker.RegisterRequest (this);
				
				string redirect;
				vapp.Redirect (rdata.Path, out redirect);
				host.ProcessRequest (requestId, localEP.Address.Address, localEP.Port,
						remoteEP.Address.Address, remoteEP.Port, rdata.Verb,
						rdata.Path, rdata.QueryString,
						rdata.Protocol, rdata.InputBuffer, redirect);
			} catch (Exception e) {
				bool ignore = ((e is RequestLineException) || (e is IOException));
				if (!ignore)
					Console.WriteLine (e);

				try {
					if (!ignore) {
						byte [] error = HttpErrors.ServerError ();
						Write (error, 0, error.Length);
					}
				} catch {}
				try {
					Close ();
				} catch {}

				if (broker != null && requestId != -1)
					broker.UnregisterRequest (requestId);
			}
		}