public void DestroyHost(IApplicationHost host) { // Called when the host appdomain is being unloaded for (int i = vpathToHost.Count - 1; i >= 0; i--) { VPathToHost v = (VPathToHost)vpathToHost [i]; if (v.TryClearHost(host)) { break; } } }
public VPathToHost GetApplicationForPath(string vhost, int port, string path, bool defaultToRoot) { VPathToHost bestMatch = null; int bestMatchLength = 0; // Console.WriteLine("GetApplicationForPath({0},{1},{2},{3})", vhost, port, // path, defaultToRoot); for (int i = vpathToHost.Count - 1; i >= 0; i--) { VPathToHost v = (VPathToHost)vpathToHost [i]; int matchLength = v.vpath.Length; if (matchLength <= bestMatchLength || !v.Match(vhost, port, path)) { continue; } bestMatchLength = matchLength; bestMatch = v; } if (bestMatch != null) { lock (bestMatch) { if (bestMatch.AppHost == null) { bestMatch.CreateHost(this, webSource); } } return(bestMatch); } if (defaultToRoot) { return(GetApplicationForPath(vhost, port, "/", false)); } if (verbose) { Console.WriteLine("No application defined for: {0}:{1}{2}", vhost, port, path); } return(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); } } }