Ejemplo n.º 1
0
        public MyListenerContext GetContext()
        {
            System.Threading.Thread.Sleep(500);//为什么必须延迟一会才行?

            acceptedSocket = listenSocket.Accept();
            if (NewConnectionComingEvent != null)
            {
                NewConnectionComingEvent();
            }

            MyListenerContext r = new MyListenerContext();

            var req = GetHttpRequest();

            r.Request = req;

            var resp = new MyHttpResponse();

            if (acceptedSocket != null)
            {
                resp.OutputStream = new SocketStream(acceptedSocket, req, resp);
            }
            r.Response = resp;

            return(r);
        }
Ejemplo n.º 2
0
        public MyListenerContext GetContext()
        {
            MyListenerContext r = new MyListenerContext();

            var buildInContext = httpListener.GetContext();

            var req = buildInContext.Request;

            r.Request = new MyHttpRequest
            {
                ContentEncoding = req.ContentEncoding,
                ContentLength64 = req.ContentLength64,
                ContentType     = req.ContentType,
                HasEntityBody   = req.HasEntityBody,
                Headers         = req.Headers,
                HttpMethod      = req.HttpMethod,
                InputStream     = req.InputStream,
                RemoteEndPoint  = req.RemoteEndPoint,
                Url             = req.Url,
                UserAgent       = req.UserAgent,
                ProtocolVersion = req.ProtocolVersion
            };

            var resp = buildInContext.Response;

            r.Response = new MyHttpResponse
            {
                ContentLength64   = resp.ContentLength64,
                Headers           = resp.Headers,
                OutputStream      = resp.OutputStream,
                SendChunked       = resp.SendChunked,
                StatusCode        = resp.StatusCode,
                StatusDescription = resp.StatusDescription
            };

            return(r);
        }