Наследование: IDisposable
Пример #1
0
            public ListenerContext(HttpServer server)
            {
                Server = server;
                EndPoints = server.EndPoints.ToArray();
                ListeningSockets = new Socket[EndPoints.Length];

                OnAcceptBegan = _OnAcceptBegan;
            }
Пример #2
0
        static Program()
        {
            Server = new HttpServer(Scheduler) {
                EndPoints = {
                    new IPEndPoint(IPAddress.Any, 10337)
                }
            };

            Server.SocketOpened += OnSocketOpened;
            Server.SocketClosed += OnSocketClosed;
        }
Пример #3
0
        static IEnumerator<object> RequestTask(HttpServer.Request request)
        {
            Console.WriteLine("{0} <- {1} {2}", request.LocalEndPoint, request.RemoteEndPoint, request.Line.Uri);

            using (request) {
                if (request.Line.Uri.PathAndQuery == "/favicon.ico") {
                    request.Response.StatusCode = 404;
                    request.Response.StatusText = "File not found";
                    yield return request.Response.SendHeaders();
                } else {
                    yield return request.Response.SendResponse("Hello world!");
                }
            }
        }
Пример #4
0
            internal Request(
                HttpServer server, SocketDataAdapter adapter, bool shouldKeepAlive,
                RequestLine line, HeaderCollection headers, RequestBody body
            )
            {
                QueuedWhenUTC = DateTime.UtcNow;
                WeakServer = new WeakReference(server);

                LocalEndPoint = adapter.Socket.LocalEndPoint;
                RemoteEndPoint = adapter.Socket.RemoteEndPoint;

                Line = line;
                Headers = headers;
                Body = body;
                Response = new Response(this, adapter, shouldKeepAlive);

                server.OnRequestCreated(this);
            }
Пример #5
0
 internal EndPointList(HttpServer owner)
 {
     Owner = owner;
 }
Пример #6
0
        public void TearDown()
        {
            if (Server != null)
                Server.Dispose();

            if (Scheduler != null)
                Scheduler.Dispose();

            Server = null;
            Scheduler = null;
        }
Пример #7
0
        public void SetUp()
        {
            Scheduler = new TaskScheduler();
            Server = new HttpServer(Scheduler);

            var port = BasePort + PortIndex;
            PortIndex += 1;
            if (PortIndex > NumPorts)
                PortIndex = 0;

            ListenPort = new IPEndPoint(IPAddress.Any, port);
            ServerUri = String.Format("http://localhost:{0}/", port);
        }