示例#1
0
        void RunInternal(object state)
        {
            RequestData rdata = initial.RequestData;

            initial.FreeBuffer();
            string      vhost = null;        // TODO: read the headers in InitialWorkerRequest
            int         port  = localEP.Port;
            VPathToHost vapp;

            try {
                vapp = server.GetApplicationForPath(vhost, port, rdata.Path, true);
            } catch (Exception e) {
                //
                // This happens if the assembly is not in the GAC, so we report this
                // error here.
                //
                Logger.Write(e);
                return;
            }

            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);

            try {
                string redirect;
                vapp.Redirect(rdata.Path, out redirect);
                host.ProcessRequest(requestId, localEP,
                                    remoteEP, rdata.Verb,
                                    rdata.Path, rdata.QueryString,
                                    rdata.Protocol, rdata.InputBuffer, redirect, sock.Handle, ssl);
            } catch (FileNotFoundException fnf) {
                // We print this one, as it might be a sign of a bad deployment
                // once we require the .exe and Mono.WebServer in bin or the GAC.
                Logger.Write(fnf);
            } catch (IOException) {
                // This is ok (including EndOfStreamException)
            } catch (Exception e) {
                Logger.Write(e);
            }
        }
        private bool AddHeader(string name, string value, bool isHeader, object userData)
        {
            TransportRequest req = userData as TransportRequest;

            //if we did not find a route yet
            if (!IsHostFound(req))
            {
                req.tempKeys.Add(new KeyValuePair()
                {
                    Key      = name,
                    Value    = value,
                    IsHeader = isHeader
                });

                if (req.VHost == null && name == "SERVER_NAME")
                {
                    req.VHost = value;
                }
                if (req.VPort == -1 && name == "SERVER_PORT")
                {
                    int.TryParse(value, out req.VPort);
                }
                if (req.VPath == null && name == "SCRIPT_NAME")
                {
                    req.VPath = value;
                }

                if (req.VHost != null && req.VPort != -1 && req.VPath != null)
                {
                    GetRoute(req, req.VHost, req.VPort, req.VPath);

                    if (IsHostFound(req))
                    {
                        CreateRequest(req);

                        foreach (KeyValuePair pair in req.tempKeys)
                        {
                            if (pair.IsHeader)
                            {
                                AddHeader(req, pair.Key, pair.Value);
                            }
                            else
                            {
                                AddServerVariable(req, pair.Key, pair.Value);
                            }
                        }
                    }
                    else
                    {
                        Logger.Write(LogLevel.Error, "Can't find app {0}:{1} {2}", req.VHost, req.VPort, req.VPath);
                        //TODO: Send EndRequest with error message
                        //SendError (request.Hash, req.RequestNumber, Strings.Connection_AbortRecordReceived);
                        byte[] notFound = HttpErrors.NotFound(req.VPath);
                        SendOutput(req.Hash, req.RequestNumber, notFound, notFound.Length);
                        EndRequest(req.Hash, req.RequestNumber, 0);
                        return(false);
                    }
                }
            }
            else
            {
                if (isHeader)
                {
                    AddHeader(req, name, value);
                }
                else
                {
                    AddServerVariable(req, name, value);
                }
            }

            return(true);
        }