Пример #1
0
        public override void Connected(IServer server, ConnectedEventArgs e)
        {
            base.Connected(server, e);
            e.Session.Socket.NoDelay = true;
            var token = new HttpToken();

            token.Db        = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
            token.NextQueue = NextQueueGroup.Next();
            e.Session.Tag   = token;
        }
Пример #2
0
 public ValueTask Json(PipeStream stream, HttpToken token, ISession session)
 {
     stream.Write(_jsonPreamble.Data, 0, _jsonPreamble.Length);
     GMTDate.Default.Write(stream);
     System.Text.Json.JsonSerializer.Serialize <JsonMessage>(GetUtf8JsonWriter(stream, token), new JsonMessage {
         message = "Hello, World!"
     }, SerializerOptions);
     OnCompleted(stream, session, token);
     return(ValueTask.CompletedTask);
 }
Пример #3
0
        public override void Connected(IServer server, ConnectedEventArgs e)
        {
            base.Connected(server, e);
            e.Session.Socket.NoDelay = true;
            var token = new HttpToken();

            token.ThreadDispatcher = RequestDispatchs.Next();
            token.Session          = e.Session;
            token.Db      = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
            e.Session.Tag = token;
        }
 public Task Default(PipeStream stream, HttpToken token, ISession session)
 {
     stream.Write(_defaultPreamble.Data, 0, _defaultPreamble.Length);
     token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
     GMTDate.Default.Write(stream);
     token.ContentPostion = stream.CacheLength;
     stream.Write("<b> beetlex server</b><hr/>");
     stream.Write("path not found!");
     OnCompleted(stream, session, token);
     return(Task.CompletedTask);
 }
Пример #5
0
        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            base.SessionReceive(server, e);
            PipeStream pipeStream = e.Session.Stream.ToPipeStream();
            HttpToken  token      = (HttpToken)e.Session.Tag;
            var        result     = pipeStream.IndexOfLine();

            while (result.End != null)
            {
                if (result.Length == 2)
                {
                    pipeStream.ReadFree(result.Length);
                    OnStartRequest(token.CurrentRequest, e.Session, token, pipeStream);
                }
                else
                {
                    if (token.CurrentRequest == null)
                    {
                        var    request = new RequestData();
                        byte[] buffer  = null;
                        buffer = new byte[result.Length];
                        pipeStream.Read(buffer, 0, result.Length);
                        request.Data = new ArraySegment <byte>(buffer, 0, result.Length);
                        AnalysisAction(request);
                        if (request.Action == ActionType.Plaintext)
                        {
                            token.CurrentRequest = request;
                        }
                        else
                        {
                            token.CurrentRequest = request;
                            pipeStream.ReadFree((int)pipeStream.Length);
                            OnStartRequest(request, e.Session, token, pipeStream);
                            return;
                        }
                    }
                    else
                    {
                        pipeStream.ReadFree(result.Length);
                    }
                }
                if (pipeStream.Length > 0)
                {
                    result = pipeStream.IndexOfLine();
                }
                else
                {
                    break;
                }
            }
        }
Пример #6
0
        private void OnCompleted(PipeStream stream, ISession session, HttpToken token)
        {
            var type = token.CurrentRequest.Action;

            if (type != ActionType.Plaintext && type != ActionType.Json)
            {
                token.FullLength((stream.CacheLength - token.ContentPostion).ToString());
            }
            if (token.Requests.IsEmpty && stream.Length == 0)
            {
                session.Stream.Flush();
            }
            token.CurrentRequest = null;
        }
Пример #7
0
        public async void db(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await mPgsql.LoadSingleQueryRow();

                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
            }
            catch (Exception e_)
            {
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #8
0
        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            base.SessionReceive(server, e);
            PipeStream pipeStream = e.Session.Stream.ToPipeStream();
            HttpToken  token      = (HttpToken)e.Session.Tag;

            //RequestWork work = new RequestWork();
            //work.Handler = this;
            //work.Session = e.Session;
            //work.Stream = pipeStream;
            //work.Token = token;
            //token.NextQueue.Enqueue(work);
            OnProcess(pipeStream, token, e.Session);
        }
Пример #9
0
        private static Utf8JsonWriter GetUtf8JsonWriter(PipeStream stream, HttpToken token)
        {
            var buffer = stream.CreateBufferWriter();

            if (token.Utf8JsonWriter == null)
            {
                token.Utf8JsonWriter = new Utf8JsonWriter(buffer, new JsonWriterOptions {
                    SkipValidation = true
                });
            }
            var writer = token.Utf8JsonWriter;

            writer.Reset(buffer);
            return(writer);
        }
Пример #10
0
        public async Task db(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await token.Db.LoadSingleQueryRow();

                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"db error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #11
0
        public async ValueTask db(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await token.Db.LoadSingleQueryRow();

                System.Text.Json.JsonSerializer.Serialize <World>(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"db error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #12
0
        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            base.SessionReceive(server, e);
            PipeStream pipeStream = e.Session.Stream.ToPipeStream();
            HttpToken  token      = (HttpToken)e.Session.Tag;
            var        result     = pipeStream.IndexOf(_line.Data);

            while (result.End != null)
            {
                if (result.Length == 2)
                {
                    if (token.CurrentRequest != null)
                    {
                        token.Requests.Enqueue(token.CurrentRequest);
                        token.CurrentRequest = null;
                    }
                    pipeStream.ReadFree(result.Length);
                }
                else
                {
                    if (token.CurrentRequest == null)
                    {
                        token.CurrentRequest = new RequestData();
                        var buffer = System.Buffers.ArrayPool <byte> .Shared.Rent(result.Length);

                        pipeStream.Read(buffer, 0, result.Length);
                        token.CurrentRequest.Data = new ArraySegment <byte>(buffer, 0, result.Length);
                    }
                    else
                    {
                        pipeStream.ReadFree(result.Length);
                    }
                }
                if (pipeStream.Length > 0)
                {
                    result = pipeStream.IndexOf(_line.Data);
                }
                else
                {
                    break;
                }
            }
            if (pipeStream.Length == 0 && token.CurrentRequest == null)
            {
                ProcessReqeusts(token, pipeStream, e.Session);
            }
        }
Пример #13
0
 public ValueTask Json(PipeStream stream, HttpToken token, ISession session)
 {
     if (Program.Debug)
     {
         System.Text.Json.JsonSerializer.Serialize <JsonMessage>(GetUtf8JsonWriter(stream, token), new JsonMessage {
             message = "Hello, World!"
         }, SerializerOptions);
     }
     else
     {
         SpanJson.JsonSerializer.NonGeneric.Utf8.SerializeAsync(new JsonMessage {
             message = "Hello, World!"
         }, stream);
     }
     OnCompleted(stream, session, token);
     return(ValueTask.CompletedTask);
 }
Пример #14
0
        public async ValueTask db(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await token.Db.LoadSingleQueryRow();

                stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
                GMTDate.Default.Write(stream);
                token.ContentPostion = stream.CacheLength;
                System.Text.Json.JsonSerializer.Serialize <World>(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"db error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #15
0
        public async Task fortunes(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await token.Db.LoadFortunesRows();

                if (Program.Debug)
                {
                    var html = token.GetHtmlBufferWriter();
                    html.Reset();
                    html.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
                    foreach (var item in data)
                    {
                        html.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
                        WriteNumeric(html, (uint)item.Id);
                        html.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
                        html.Write(HtmlEncoder.Encode(item.Message));
                        html.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
                    }
                    html.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
                    stream.Write(html.Data, 0, html.Length);
                }
                else
                {
                    stream.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
                    foreach (var item in data)
                    {
                        stream.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
                        WriteNumeric(stream, (uint)item.Id);
                        stream.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
                        stream.Write(HtmlEncoder.Encode(item.Message));
                        stream.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
                    }
                    stream.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
                }
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"fortunes error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #16
0
        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            base.SessionReceive(server, e);
            PipeStream pipeStream = e.Session.Stream.ToPipeStream();
            HttpToken  token      = (HttpToken)e.Session.Tag;

            if (Program.Debug || Program.UpDB)
            {
                RequestWork work = new RequestWork();
                work.Handler = this;
                work.Session = e.Session;
                work.Stream  = pipeStream;
                work.Token   = token;
                token.NextQueue.Enqueue(work);
            }
            else
            {
                OnProcess(pipeStream, token, e.Session);
            }
        }
Пример #17
0
        public async ValueTask updates(string queryString, PipeStream stream, HttpToken token, ISession session)
        {
            int count = 1;

            if (!string.IsNullOrEmpty(queryString))
            {
                var values = queryString.Split('=');
                if (values.Length > 1)
                {
                    if (int.TryParse(values[1], out int size))
                    {
                        count = size;
                    }
                }
            }
            if (count > 500)
            {
                count = 500;
            }
            if (count < 1)
            {
                count = 1;
            }
            try
            {
                var data = await token.Db.LoadMultipleUpdatesRows(count);

                stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
                GMTDate.Default.Write(stream);
                token.ContentPostion = stream.CacheLength;
                System.Text.Json.JsonSerializer.Serialize <World[]>(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"updates error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #18
0
        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            base.SessionReceive(server, e);
            PipeStream pipeStream = e.Session.Stream.ToPipeStream();
            HttpToken  token      = (HttpToken)e.Session.Tag;
            var        result     = pipeStream.IndexOf(_line.Data);

            if (result.End == null)
            {
                return;
            }
            int len = result.Length;

            pipeStream.Read(token.Buffer, 0, len);
            ReadOnlySpan <byte> line   = new Span <byte>(token.Buffer, 0, len);
            ReadOnlySpan <byte> http   = line;
            ReadOnlySpan <byte> method = line;
            ReadOnlySpan <byte> url    = line;
            int offset2 = 0;
            int count   = 0;

            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] == _Space)
                {
                    if (count != 0)
                    {
                        url     = line.Slice(offset2, i - offset2);
                        offset2 = i + 1;
                        http    = line.Slice(offset2, line.Length - offset2 - 2);
                        break;
                    }
                    method  = line.Slice(offset2, i - offset2);
                    offset2 = i + 1;
                    count++;
                }
            }
            OnStartLine(http, method, url, e.Session, token, pipeStream);
        }
        public async Task caching(string queryString, PipeStream stream, HttpToken token, ISession session)
        {
            int count = 1;

            if (!string.IsNullOrEmpty(queryString))
            {
                var values = queryString.Split('=');
                if (values.Length > 1)
                {
                    if (int.TryParse(values[1], out int size))
                    {
                        count = size;
                    }
                }
            }
            if (count > 500)
            {
                count = 500;
            }
            if (count < 1)
            {
                count = 1;
            }
            try
            {
                var data = await token.Db.LoadCachedQueries(count);

                stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
                GMTDate.Default.Write(stream);
                token.ContentPostion = stream.CacheLength;
                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
            }
            catch (Exception e_)
            {
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #20
0
        private void OnWriteContentLength(PipeStream stream, HttpToken token)
        {
            var action = token.CurrentRequest.Action;

            if (action == ActionType.Json)
            {
                stream.Write(_jsonPreamble.Data, 0, _jsonPreamble.Length);
                stream.Write(_2line, 0, 4);
            }
            else if (action == ActionType.Plaintext)
            {
                stream.Write(_plaintextPreamble.Data, 0, _plaintextPreamble.Length);
                stream.Write(_2line, 0, 4);
            }
            else
            {
                stream.Write(_headerContentLength.Data, 0, _headerContentLength.Length);
                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
                stream.Write(_2line, 0, 4);
                token.ContentPostion = stream.CacheLength;
            }
        }
Пример #21
0
        private void OnProcess(PipeStream pipeStream, HttpToken token, ISession sessino)
        {
            var line                   = _line.AsSpan();
            int len                    = (int)pipeStream.FirstBuffer.Length;
            var receiveData            = pipeStream.FirstBuffer.Memory.Span;
            ReadOnlySpan <byte> http   = line;
            ReadOnlySpan <byte> method = line;
            ReadOnlySpan <byte> url    = line;
            int offset2                = 0;
            int count                  = 0;

            for (int i = 0; i < len; i++)
            {
                if (receiveData[i] == line[0])
                {
                    http = receiveData.Slice(offset2, i - offset2);
                    break;
                }
                else
                {
                    if (receiveData[i] == _Space)
                    {
                        if (count != 0)
                        {
                            url     = receiveData.Slice(offset2, i - offset2);
                            offset2 = i + 1;
                        }
                        else
                        {
                            method  = receiveData.Slice(offset2, i - offset2);
                            offset2 = i + 1;
                            count++;
                        }
                    }
                }
            }
            OnStartLine(http, method, url, sessino, token, pipeStream);
        }
Пример #22
0
        private Task OnProcess(RequestData requestData, PipeStream pipeStream, HttpToken token, ISession sessino)
        {
            var line                   = _line.AsSpan();
            int len                    = requestData.Data.Count;
            var receiveData            = requestData.GetSpan();
            ReadOnlySpan <byte> http   = line;
            ReadOnlySpan <byte> method = line;
            ReadOnlySpan <byte> url    = line;
            int offset2                = 0;
            int count                  = 0;

            for (int i = 0; i < len; i++)
            {
                if (receiveData[i] == line[0])
                {
                    http = receiveData.Slice(offset2, i - offset2);
                    break;
                }
                else
                {
                    if (receiveData[i] == _Space)
                    {
                        if (count != 0)
                        {
                            url     = receiveData.Slice(offset2, i - offset2);
                            offset2 = i + 1;
                        }
                        else
                        {
                            method  = receiveData.Slice(offset2, i - offset2);
                            offset2 = i + 1;
                            count++;
                        }
                    }
                }
            }
            return(OnStartLine(http, method, url, sessino, token, pipeStream));
        }
Пример #23
0
        public virtual async Task OnStartRequest(RequestData data, ISession session, HttpToken token, PipeStream stream)
        {
            OnWriteHeader(stream, token, data.Action);
            ActionType type = data.Action;

            if (type == ActionType.Plaintext)
            {
                await Plaintext(stream, token, session);
            }
            else if (type == ActionType.Json)
            {
                await Json(stream, token, session);
            }
            else if (type == ActionType.Db)
            {
                await db(stream, token, session);
            }
            else if (type == ActionType.Queries)
            {
                await queries(data.QueryString, stream, token, session);
            }
            else if (type == ActionType.Caching)
            {
                await caching(data.QueryString, stream, token, session);
            }
            else if (type == ActionType.Updates)
            {
                await updates(data.QueryString, stream, token, session);
            }
            else if (type == ActionType.Fortunes)
            {
                await fortunes(stream, token, session);
            }
            else
            {
                await Default(stream, token, session);
            }
        }
Пример #24
0
        public async void fortunes(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await token.Db.LoadFortunesRows();

                stream.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
                foreach (var item in data)
                {
                    stream.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
                    stream.Write(item.Id.ToString(CultureInfo.InvariantCulture));
                    stream.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
                    stream.Write(System.Web.HttpUtility.HtmlEncode(item.Message));
                    stream.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
                }
                stream.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
            }
            catch (Exception e_)
            {
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #25
0
        public async Task fortunes(PipeStream stream, HttpToken token, ISession session)
        {
            try
            {
                var data = await token.Db.LoadFortunesRows();

                stream.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
                foreach (var item in data)
                {
                    stream.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
                    stream.Write(item.Id.ToString(CultureInfo.InvariantCulture));
                    stream.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
                    stream.Write(System.Web.HttpUtility.HtmlEncode(item.Message));
                    stream.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
                }
                stream.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"fortunes error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #26
0
        public async void updates(string queryString, PipeStream stream, HttpToken token, ISession session)
        {
            int count = 1;

            if (!string.IsNullOrEmpty(queryString))
            {
                var values = queryString.Split('=');
                if (values.Length > 1)
                {
                    if (int.TryParse(values[1], out int size))
                    {
                        count = size;
                    }
                }
            }
            if (count > 500)
            {
                count = 500;
            }
            if (count < 1)
            {
                count = 1;
            }
            try
            {
                var data = await token.Db.LoadMultipleUpdatesRows(count);

                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
            }
            catch (Exception e_)
            {
                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"updates error {e_.Message}@{e_.StackTrace}");
                stream.Write(e_.Message);
            }
            OnCompleted(stream, session, token);
        }
Пример #27
0
        private void OnProcess(PipeStream pipeStream, HttpToken token, ISession sessino)
        {
            var result = pipeStream.IndexOf(_line.Data);

            if (result.End == null)
            {
                return;
            }
            int len = result.Length;

            pipeStream.Read(token.Buffer, 0, len);
            ReadOnlySpan <byte> line   = new Span <byte>(token.Buffer, 0, len);
            ReadOnlySpan <byte> http   = line;
            ReadOnlySpan <byte> method = line;
            ReadOnlySpan <byte> url    = line;
            int offset2 = 0;
            int count   = 0;

            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] == _Space)
                {
                    if (count != 0)
                    {
                        url     = line.Slice(offset2, i - offset2);
                        offset2 = i + 1;
                        http    = line.Slice(offset2, line.Length - offset2 - 2);
                        break;
                    }
                    method  = line.Slice(offset2, i - offset2);
                    offset2 = i + 1;
                    count++;
                }
            }
            OnStartLine(http, method, url, sessino, token, pipeStream);
        }
Пример #28
0
 public void Default(ReadOnlySpan <byte> url, PipeStream stream, HttpToken token, ISession session)
 {
     stream.Write("<b> beetlex server</b><hr/>");
     stream.Write($"{Encoding.ASCII.GetString(url)} not found!");
     OnCompleted(stream, session, token);
 }
Пример #29
0
 private void OnCompleted(PipeStream stream, ISession session, HttpToken token)
 {
     stream.ReadFree((int)stream.Length);
     token.FullLength((stream.CacheLength - token.ContentPostion).ToString());
     session.Stream.Flush();
 }
Пример #30
0
        public virtual void OnStartLine(ReadOnlySpan <byte> http, ReadOnlySpan <byte> method, ReadOnlySpan <byte> url, ISession session, HttpToken token, PipeStream stream)
        {
            if (!Program.Debug)
            {
                UpdateCommandsCached.Init();
                if (Program.UpDB)
                {
                    DBConnectionGroupPool.Init(64, RawDb._connectionString);
                }
                else
                {
                    DBConnectionGroupPool.Init(256, RawDb._connectionString);
                }
            }
            int queryIndex = AnalysisUrl(url);
            ReadOnlySpan <byte> baseUrl     = default;
            ReadOnlySpan <byte> queryString = default;

            if (queryIndex > 0)
            {
                baseUrl     = url.Slice(0, queryIndex);
                queryString = url.Slice(queryIndex + 1, url.Length - queryIndex - 1);
            }
            else
            {
                baseUrl = url;
            }
            OnWriteHeader(stream, token);
            if (baseUrl.Length == _path_Plaintext.Length && baseUrl.StartsWith(_path_Plaintext))
            {
                stream.Write(_headerContentTypeText.Data, 0, _headerContentTypeText.Length);
                OnWriteContentLength(stream, token);
                Plaintext(url, stream, token, session);
            }
            else if (baseUrl.Length == _path_Json.Length && baseUrl.StartsWith(_path_Json))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                Json(url, stream, token, session);
            }
            else if (baseUrl.Length == _path_Db.Length && baseUrl.StartsWith(_path_Db))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                db(stream, token, session);
            }
            else if (baseUrl.Length == _path_Queries.Length && baseUrl.StartsWith(_path_Queries))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                queries(Encoding.ASCII.GetString(queryString), stream, token, session);
            }

            else if (baseUrl.Length == _cached_worlds.Length && baseUrl.StartsWith(_cached_worlds))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                caching(Encoding.ASCII.GetString(queryString), stream, token, session);
            }

            else if (baseUrl.Length == _path_Updates.Length && baseUrl.StartsWith(_path_Updates))
            {
                stream.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
                OnWriteContentLength(stream, token);
                updates(Encoding.ASCII.GetString(queryString), stream, token, session);
            }
            else if (baseUrl.Length == _path_Fortunes.Length && baseUrl.StartsWith(_path_Fortunes))
            {
                stream.Write(_headerContentTypeHtml.Data, 0, _headerContentTypeHtml.Length);
                OnWriteContentLength(stream, token);
                fortunes(stream, token, session);
            }
            else
            {
                stream.Write(_headerContentTypeHtml.Data, 0, _headerContentTypeHtml.Length);
                OnWriteContentLength(stream, token);
                Default(url, stream, token, session);
            }
        }