示例#1
0
        void _run()
        {
            byte[] msg = new byte[2048];
            stream.ReadTimeout = server.ReadTimeout;
            int    l   = stream.Read(msg, 0, msg.Length);
            string txt = Encoding.Default.GetString(msg);

            txt = txt.Trim('\0');
            int headEnd = txt.IndexOf("\r\n\r\n");

            if (headEnd < 0)
            {
                headEnd = txt.Length - 1;
            }
            string          head     = txt.Substring(0, headEnd);
            HttpRequestHead httpHead = new HttpRequestHead(head);

            Log.WriteLine(LType.HttpInfo, "{2}: {0} {1}{3}User-Agent: {4}",
                          httpHead.Method, httpHead.Path, client.Client.RemoteEndPoint, Environment.NewLine, httpHead.UserAgent);

            RequestHandler handler = new RequestHandler(this.server, httpHead);

            this.server.Handle(handler);
            if (!handler.Handled)
            {
                handler.Handle();
            }
            HttpResponse resp = handler.Response;

            resp.Write(stream);
            stream.Close();

            client.Close();
            Log.WriteLine(LType.NetInfo, "Connection closed");
        }
示例#2
0
        public RequestHandler(HttpServer server, HttpRequestHead head)
        {
            string fName;
            string argLine;
            int    pos = head.Path.IndexOf('?');

            this.Head   = head;
            this.Server = server;
            if (pos >= 0)
            {
                fName   = head.Path.Substring(0, pos);
                argLine = head.Path.Substring(pos + 1);
            }
            else
            {
                fName   = head.Path;
                argLine = "";
            }
            Args     = HttpParse.ParseArgumentLine(argLine);
            FileName = fName;

            FileInfo = new FileInfo(Path.Combine(server.WwwDir, fName.TrimStart('/')));
        }