예제 #1
0
        public bool Consume(Baton baton, Action<Frame, Exception> callback)
        {
            for (; ;)
            {
                switch (_mode)
                {
                    case Mode.StartLine:
                        if (baton.RemoteIntakeFin)
                        {
                            _mode = Mode.Terminated;
                            return false;
                        }

                        if (!TakeStartLine(baton))
                        {
                            return false;
                        }

                        _mode = Mode.MessageHeader;
                        break;

                    case Mode.MessageHeader:
                        if (baton.RemoteIntakeFin)
                        {
                            _mode = Mode.Terminated;
                            return false;
                        }

                        var endOfHeaders = false;
                        while (!endOfHeaders)
                        {
                            if (!TakeMessageHeader(baton, out endOfHeaders))
                            {
                                return false;
                            }
                        }

                        var resumeBody = HandleExpectContinue(callback);
                        _messageBody = MessageBody.For(
                            _httpVersion,
                            _requestHeaders,
                            () =>
                            {
                                try
                                {
                                    if (Consume(baton, resumeBody))
                                        return;
                                }
                                catch (Exception ex)
                                {
                                    resumeBody.Invoke(this, ex);
                                    return;
                                }
                                resumeBody.Invoke(this, null);
                            });
                        _keepAlive = _messageBody.RequestKeepAlive;
                        _mode = Mode.MessageBody;
                        baton.Free();
                        Execute();
                        return true;

                    case Mode.MessageBody:
                        return _messageBody.Consume(baton, ex => callback(this, ex));

                    case Mode.Terminated:
                        return false;
                }
            }
        }
예제 #2
0
        public bool Consume(Baton baton, Action <Frame, Exception> callback)
        {
            for (; ;)
            {
                switch (_mode)
                {
                case Mode.StartLine:
                    if (baton.RemoteIntakeFin)
                    {
                        _mode = Mode.Terminated;
                        return(false);
                    }

                    if (!TakeStartLine(baton))
                    {
                        return(false);
                    }

                    _mode = Mode.MessageHeader;
                    break;

                case Mode.MessageHeader:
                    if (baton.RemoteIntakeFin)
                    {
                        _mode = Mode.Terminated;
                        return(false);
                    }

                    var endOfHeaders = false;
                    while (!endOfHeaders)
                    {
                        if (!TakeMessageHeader(baton, out endOfHeaders))
                        {
                            return(false);
                        }
                    }

                    var resumeBody = HandleExpectContinue(callback);
                    _messageBody = MessageBody.For(
                        _httpVersion,
                        _requestHeaders,
                        () =>
                    {
                        try
                        {
                            if (Consume(baton, resumeBody))
                            {
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            resumeBody.Invoke(this, ex);
                            return;
                        }
                        resumeBody.Invoke(this, null);
                    });
                    _keepAlive = _messageBody.RequestKeepAlive;
                    _mode      = Mode.MessageBody;
                    baton.Free();
                    Execute();
                    return(true);

                case Mode.MessageBody:
                    return(_messageBody.Consume(baton, ex => callback(this, ex)));

                case Mode.Terminated:
                    return(false);
                }
            }
        }