public void ProcessRequest(int reqId, long localEPAddr, int localEPPort, long remoteEPAdds,
                                   int remoteEPPort, string verb, string path,
                                   string queryString, string protocol, byte [] inputBuffer, string redirect)
        {
            XSPRequestBroker broker   = (XSPRequestBroker)RequestBroker;
            IPEndPoint       localEP  = new IPEndPoint(localEPAddr, localEPPort);
            IPEndPoint       remoteEP = new IPEndPoint(remoteEPAdds, remoteEPPort);
            XSPWorkerRequest mwr      = new XSPWorkerRequest(reqId, broker, this, localEP, remoteEP, verb, path,
                                                             queryString, protocol, inputBuffer);

            string translated = mwr.GetFilePathTranslated();

            if (path [path.Length - 1] != '/' && Directory.Exists(translated))
            {
                redirect = path + '/';
            }

            if (redirect != null)
            {
                Redirect(mwr, redirect);
                broker.UnregisterRequest(reqId);
                return;
            }

            ProcessRequest(mwr);
        }
Esempio n. 2
0
        public XSPWorkerRequest(int requestId,
                                XSPRequestBroker requestBroker,
                                IApplicationHost appHost,
                                EndPoint localEP,
                                EndPoint remoteEP,
                                string verb,
                                string path,
                                string queryString,
                                string protocol,
                                byte[] inputBuffer)
            : base(appHost)
        {
            this.requestId     = requestId;
            this.requestBroker = requestBroker;
            this.remoteEP      = remoteEP;
            this.verb          = verb;
            Paths.GetPathsFromUri(path, out this.path, out pathInfo);
            this.protocol = protocol;
            if (protocol == "HTTP/1.1")
            {
                this.protocol = "HTTP/1.0";                     // Only 1.0 supported by xsp standalone.
                keepAlive     = true;
            }

            this.queryString = queryString;
            this.inputBuffer = inputBuffer;
            inputLength      = inputBuffer.Length;
            position         = 0;

            GetRequestHeaders();
            string cncHeader = (string)headers ["Connection"];

            if (cncHeader != null)
            {
                cncHeader = cncHeader.ToLower();
                if (cncHeader.IndexOf("keep-alive") != -1)
                {
                    keepAlive = true;
                }

                if (cncHeader.IndexOf("close") != -1)
                {
                    keepAlive = false;
                }
            }

            responseHeaders = new StringBuilder();
            responseHeaders.Append(serverHeader);
            response = AllocateMemoryStream();
            status   = "HTTP/1.0 200 OK\r\n";

            localPort    = ((IPEndPoint)localEP).Port;
            localAddress = ((IPEndPoint)localEP).Address.ToString();
        }
Esempio n. 3
0
 public override void CloseConnection()
 {
     WebTrace.WriteLine("CloseConnection()");
     if (requestBroker != null)
     {
         // We check for headersSent as broken user code might call
         // CloseConnection at an early stage.
         requestBroker.Close(requestId, (headersSent ? keepAlive : false));
         requestBroker = null;
         FreeMemoryStream(response);
         response = null;
     }
 }
        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);
                }
            }
        }
Esempio n. 5
0
		public override void CloseConnection ()
		{
			WebTrace.WriteLine ("CloseConnection()");
			if (requestBroker != null) {
				// We check for headersSent as broken user code might call
				// CloseConnection at an early stage.
				requestBroker.Close (requestId, (headersSent ? keepAlive : false));
				requestBroker = null;
				FreeMemoryStream (response);
				response = null;
			}
		}
Esempio n. 6
0
		public XSPWorkerRequest (int requestId, 
								XSPRequestBroker requestBroker, 
								IApplicationHost appHost, 
								EndPoint localEP,
					 			EndPoint remoteEP, 
								string verb, 
								string path, 
								string queryString, 
								string protocol, 
								byte[] inputBuffer)
			: base (appHost)
		{
			this.requestId = requestId;
			this.requestBroker = requestBroker;
			this.remoteEP = remoteEP;
			this.verb = verb;
			Paths.GetPathsFromUri (path, out this.path, out pathInfo);
			this.protocol = protocol;
			if (protocol == "HTTP/1.1") {
				this.protocol = "HTTP/1.0";	// Only 1.0 supported by xsp standalone.
				keepAlive = true;
			}

			this.queryString = queryString;
			this.inputBuffer = inputBuffer;
			inputLength = inputBuffer.Length;
			position = 0;

			GetRequestHeaders ();
			string cncHeader = (string) headers ["Connection"];
			if (cncHeader != null) {
				cncHeader = cncHeader.ToLower ();
				if (cncHeader.IndexOf ("keep-alive") != -1)
					keepAlive = true;

				if (cncHeader.IndexOf ("close") != -1)
					keepAlive = false;
			}

			responseHeaders = new StringBuilder ();
			responseHeaders.Append (serverHeader);
			response = AllocateMemoryStream ();
			status = "HTTP/1.0 200 OK\r\n";
			
			localPort = ((IPEndPoint) localEP).Port;
			localAddress = ((IPEndPoint) localEP).Address.ToString();
		}