Exemple #1
0
		void InnerRun ()
		{
			requestId = -1;
			broker = null;
			
			var rr = new RequestReader (client);
			if (rr.ShuttingDown) {
				Close ();
				server.Stop ();
				return;
			}

			string vhost = rr.Request.GetRequestHeader ("Host");
			int port = -1;
			if (vhost != null) {
				int lead = vhost.IndexOf('[');
				int follow = lead >= 0 ? vhost.IndexOf(']') : -1;
				if (follow > lead) {
					//ipv6 address
					int colon = vhost.IndexOf("]:", StringComparison.Ordinal);
					if (colon != -1) {
						Int32.TryParse (vhost.Substring (colon + 2), out port);
						vhost = vhost.Substring(0, colon + 1);
					}
				} else {
					//ipv4 or hostname
					int colon = vhost.IndexOf (':');
					if (colon != -1) {
						Int32.TryParse (vhost.Substring (colon + 1), out port);
						vhost = vhost.Substring (0, colon);
					}
				}
				if (port <= 0 || port > 65535) {
					//No port specified, Int32.TryParse failed or invalid port number
					port = 80;
				}
			}

			string vServerName = rr.Request.GetVirtualServerName () ?? vhost;

			VPathToHost vapp;
			string vpath = rr.GetUriPath ();
			string path = rr.GetPhysicalPath ();
			if (path == null) {
				vapp = server.GetApplicationForPath (vServerName, port, vpath, false);
			} else {
				vapp = GetOrCreateApplication (vServerName, port, path, vpath);
			}

			if (vapp == null) {
				rr.NotFound ();
				Stream.Close ();
				Stream = null;
				return;
			}

			var host = (ModMonoApplicationHost) vapp.AppHost;
			if (host == null) {
				rr.NotFound ();
				Stream.Close ();
				Stream = null;
				return;
			}
			modRequest = rr.Request;
			
			if (!server.SingleApplication) {
				broker = (ModMonoRequestBroker) vapp.RequestBroker;
				broker.UnregisterRequestEvent += OnUnregisterRequest;
				requestId = broker.RegisterRequest (this);
			}
			
			host.ProcessRequest (requestId, 
					     modRequest.GetHttpVerbName(), 
					     modRequest.GetQueryString(), 
					     modRequest.GetUri(), 
					     modRequest.GetProtocol(), 
					     modRequest.GetLocalAddress(), 
					     modRequest.GetServerPort(), 
					     modRequest.GetRemoteAddress(), 
					     modRequest.GetRemotePort(), 
					     modRequest.GetRemoteName(), 
					     modRequest.GetAllHeaders(),
					     modRequest.GetAllHeaderValues(),
					     (requestId == -1) ? this : null);
		}
Exemple #2
0
        void InnerRun()
        {
            requestId = -1;
            broker    = null;

            var rr = new RequestReader(client);

            if (rr.ShuttingDown)
            {
                Close();
                server.Stop();
                return;
            }

            string vhost = rr.Request.GetRequestHeader("Host");
            int    port  = -1;

            if (vhost != null)
            {
                int lead   = vhost.IndexOf('[');
                int follow = lead >= 0 ? vhost.IndexOf(']') : -1;
                if (follow > lead)
                {
                    //ipv6 address
                    int colon = vhost.IndexOf("]:", StringComparison.Ordinal);
                    if (colon != -1)
                    {
                        Int32.TryParse(vhost.Substring(colon + 2), out port);
                        vhost = vhost.Substring(0, colon + 1);
                    }
                }
                else
                {
                    //ipv4 or hostname
                    int colon = vhost.IndexOf(':');
                    if (colon != -1)
                    {
                        Int32.TryParse(vhost.Substring(colon + 1), out port);
                        vhost = vhost.Substring(0, colon);
                    }
                }
                if (port <= 0 || port > 65535)
                {
                    //No port specified, Int32.TryParse failed or invalid port number
                    port = 80;
                }
            }

            string vServerName = rr.Request.GetVirtualServerName() ?? vhost;

            VPathToHost vapp;
            string      vpath = rr.GetUriPath();
            string      path  = rr.GetPhysicalPath();

            if (path == null)
            {
                vapp = server.GetApplicationForPath(vServerName, port, vpath, false);
            }
            else
            {
                vapp = GetOrCreateApplication(vServerName, port, path, vpath);
            }

            if (vapp == null)
            {
                rr.NotFound();
                Stream.Close();
                Stream = null;
                return;
            }

            var host = (ModMonoApplicationHost)vapp.AppHost;

            if (host == null)
            {
                rr.NotFound();
                Stream.Close();
                Stream = null;
                return;
            }
            modRequest = rr.Request;

            if (!server.SingleApplication)
            {
                broker = (ModMonoRequestBroker)vapp.RequestBroker;
                broker.UnregisterRequestEvent += OnUnregisterRequest;
                requestId = broker.RegisterRequest(this);
            }

            host.ProcessRequest(requestId,
                                modRequest.GetHttpVerbName(),
                                modRequest.GetQueryString(),
                                modRequest.GetUri(),
                                modRequest.GetProtocol(),
                                modRequest.GetLocalAddress(),
                                modRequest.GetServerPort(),
                                modRequest.GetRemoteAddress(),
                                modRequest.GetRemotePort(),
                                modRequest.GetRemoteName(),
                                modRequest.GetAllHeaders(),
                                modRequest.GetAllHeaderValues(),
                                (requestId == -1) ? this : null);
        }