BindContext() public method

public BindContext ( HttpListenerContext context ) : bool
context HttpListenerContext
return bool
Esempio n. 1
0
        void OnRead(IAsyncResult ares)
        {
            timer.Change(Timeout.Infinite, Timeout.Infinite);
            HttpConnection cnc   = (HttpConnection)ares.AsyncState;
            int            nread = -1;

            try {
                nread = stream.EndRead(ares);
                ms.Write(buffer, 0, nread);
                if (ms.Length > 32768)
                {
                    SendError("Bad request", 400);
                    Close(true);
                    return;
                }
            } catch {
                if (ms != null && ms.Length > 0)
                {
                    SendError();
                }
                if (sock != null)
                {
                    CloseSocket();
                }
                return;
            }

            if (nread == 0)
            {
                //if (ms.Length > 0)
                //	SendError (); // Why bother?
                CloseSocket();
                return;
            }

            if (ProcessInput(ms))
            {
                if (!context.HaveError)
                {
                    context.Request.FinishInitialization();
                }

                if (context.HaveError)
                {
                    SendError();
                    Close(true);
                    return;
                }

                if (!epl.BindContext(context))
                {
                    SendError("Invalid host", 400);
                    Close(true);
                }
                context_bound = true;
                return;
            }
            stream.BeginRead(buffer, 0, BufferSize, OnRead, cnc);
        }
Esempio n. 2
0
        private void OnRead(IAsyncResult ares)
        {
            HttpConnection state = (HttpConnection)ares.AsyncState;
            int            num   = -1;

            try
            {
                num = stream.EndRead(ares);
                ms.Write(buffer, 0, num);
                if (ms.Length > 32768)
                {
                    SendError("Bad request", 400);
                    Close(force_close: true);
                    return;
                }
            }
            catch
            {
                if (ms != null && ms.Length > 0)
                {
                    SendError();
                }
                if (sock != null)
                {
                    CloseSocket();
                }
                return;

                IL_009f :;
            }
            if (num == 0)
            {
                CloseSocket();
            }
            else if (ProcessInput(ms))
            {
                if (!context.HaveError)
                {
                    context.Request.FinishInitialization();
                }
                if (context.HaveError)
                {
                    SendError();
                    Close(force_close: true);
                    return;
                }
                if (!epl.BindContext(context))
                {
                    SendError("Invalid host", 400);
                    Close(force_close: true);
                }
                context_bound = true;
            }
            else
            {
                stream.BeginRead(buffer, 0, 8192, OnRead, state);
            }
        }
Esempio n. 3
0
        void OnRead(IAsyncResult ares)
        {
            // TODO: set a limit on ms length.
            HttpConnection cnc   = (HttpConnection)ares.AsyncState;
            int            nread = -1;

            try {
                nread = stream.EndRead(ares);
                ms.Write(buffer, 0, nread);
            } catch (Exception e) {
                Console.WriteLine(e);
                if (ms.Length > 0)
                {
                    SendError();
                }
                sock.Close();
                return;
            }

            if (nread == 0)
            {
                //if (ms.Length > 0)
                //	SendError (); // Why bother?
                sock.Close();
                return;
            }

            if (ProcessInput(ms))
            {
                if (!context.HaveError)
                {
                    context.Request.FinishInitialization();
                }

                if (context.HaveError)
                {
                    SendError();
                    Close();
                    return;
                }

                if (!epl.BindContext(context))
                {
                    SendError("Invalid host", 400);
                    Close();
                }
                context_bound = true;
                return;
            }
            stream.BeginRead(buffer, 0, BufferSize, OnRead, cnc);
        }
Esempio n. 4
0
        void OnReadInternal(IAsyncResult ares)
        {
            timer.Change(Timeout.Infinite, Timeout.Infinite);
            int nread = -1;

            try {
                nread = stream.EndRead(ares);
                ms.Write(buffer, 0, nread);
                if (ms.Length > 32768)
                {
                    SendError("Bad request", 400);
                    Close(true);
                    return;
                }
            } catch {
                if (ms != null && ms.Length > 0)
                {
                    SendError();
                }
                if (sock != null)
                {
                    CloseSocket();
                    Unbind();
                }
                return;
            }

            if (nread == 0)
            {
                //if (ms.Length > 0)
                //	SendError (); // Why bother?
                CloseSocket();
                Unbind();
                return;
            }

            if (ProcessInput(ms))
            {
                if (!context.HaveError)
                {
                    context.Request.FinishInitialization();
                }

                if (context.HaveError)
                {
                    SendError();
                    Close(true);
                    return;
                }

                if (!epl.BindContext(context))
                {
                    SendError("Invalid host", 400);
                    Close(true);
                    return;
                }
                HttpListener listener = context.Listener;
                if (last_listener != listener)
                {
                    RemoveConnection();
                    listener.AddConnection(this);
                    last_listener = listener;
                }

                context_bound = true;
                listener.RegisterContext(context);
                return;
            }
            stream.BeginRead(buffer, 0, BufferSize, onread_cb, this);
        }
Esempio n. 5
0
        private void OnReadInternal(IAsyncResult ares)
        {
            _timer.Change(Timeout.Infinite, Timeout.Infinite);
            var nread = -1;

            try
            {
                nread = _stream.EndRead(ares);
                _ms.Write(_buffer, 0, nread);
                if (_ms.Length > 32768)
                {
                    SendError("Bad request", 400);
                    Close(true);
                    return;
                }
            }
            catch
            {
                if (_ms != null && _ms.Length > 0)
                {
                    SendError();
                }
                if (_sock != null)
                {
                    CloseSocket();
                    Unbind();
                }
                return;
            }

            if (nread == 0)
            {
                //if (ms.Length > 0)
                //	SendError (); // Why bother?
                CloseSocket();
                Unbind();
                return;
            }

            if (ProcessInput(_ms))
            {
                if (!_context.HaveError)
                {
                    _context.Request.FinishInitialization();
                }

                if (_context.HaveError)
                {
                    SendError();
                    Close(true);
                    return;
                }

                if (!_epl.BindContext(_context))
                {
                    SendError("Invalid host", 400);
                    Close(true);
                    return;
                }
                var listener = _context.Listener;
                if (_lastListener != listener)
                {
                    RemoveConnection();
                    listener.AddConnection(this);
                    _lastListener = listener;
                }

                _contextBound = true;
                listener.RegisterContext(_context);
                return;
            }
            _stream.BeginRead(_buffer, 0, BufferSize, _onreadCb, this);
        }