Пример #1
0
        private async Task HandleSession(ConnectionEventArgs e)
        {
            using (Logger.Enter($"Receiving new connection from: {e.Socket.RemoteEndPoint}"))
            {
                var clientConnection = e.Stream;

                Events.Raise(OnClientConnect, this, e);
                var session = new Session(clientConnection, _listener.Endpoint, this);
                try
                {
                    await StateMachine.RunAsync(session).WithoutCapturingContext();
                }
                catch (Exception ex)
                {
                    Logger.LogData(TraceEventType.Error, ex);
                    await session.ClientHandler.SendErrorAsync(
                        ProtocolVersion.Parse("HTTP/1.1"),
                        HttpStatusCode.BadGateway, "Bad Gateway", ex.ToString())
                    .WithoutCapturingContext();
                }
                finally
                {
                    ((NetworkStream)clientConnection)?.Close(1);
                }
            }
        }
Пример #2
0
        public static StatusLine Parse(string line)
        {
            var ifs         = line.IndexOf(' ');
            var ils         = line.IndexOf(' ', ifs + 1);
            var version     = ProtocolVersion.Parse(line.Substring(0, ifs));
            var code        = line.Substring(ifs + 1, ils - ifs - 1);
            var description = line.Substring(ils + 1);

            return(new StatusLine(version, code, description));
        }
Пример #3
0
        public static RequestLine Parse(string line)
        {
            var ifs     = line.IndexOf(' ');
            var ils     = line.IndexOf(' ', ifs + 1);
            var verb    = line.Substring(0, ifs);
            var uri     = line.Substring(ifs + 1, ils - ifs - 1);
            var version = ProtocolVersion.Parse(line.Substring(ils + 1));

            return(new RequestLine(verb, uri, version));
        }