コード例 #1
0
        protected override void ChannelRead0(IChannelHandlerContext ctx, IFullHttpRequest msg)
        {
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug($"Uri:{msg.Uri}");
                logger.LogDebug($"Content:{msg.Content.ToString(Encoding.UTF8)}");
            }
            JT808HttpResponse jT808HttpResponse = null;

            if (jT808WebAPIService.HandlerDict.TryGetValue(msg.Uri, out var funcHandler))
            {
                jT808HttpResponse = funcHandler(new JT808HttpRequest()
                {
                    Json = msg.Content.ToString(Encoding.UTF8)
                });
            }
            else
            {
                jT808HttpResponse = jT808WebAPIService.NotFoundHttpResponse();
            }
            if (jT808HttpResponse != null)
            {
                WriteResponse(ctx, Unpooled.WrappedBuffer(jT808HttpResponse.Data), TypeJson, jT808HttpResponse.Data.Length);
            }
        }
コード例 #2
0
        protected override void ChannelRead0(IChannelHandlerContext ctx, IFullHttpRequest msg)
        {
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug($"Uri:{msg.Uri}");
                logger.LogDebug($"Content:{msg.Content.ToString(Encoding.UTF8)}");
            }
            JT808HttpResponse jT808HttpResponse = null;

            if (!jT808WebApiAuthorization.Authorization(msg, out var principal))
            {
                jT808HttpResponse = jT808MsgIdHttpHandlerBase.AuthFailHttpResponse();
            }
            else
            {
                var    uriSpan = msg.Uri.AsSpan();
                var    index   = uriSpan.IndexOf('?');
                string uri     = msg.Uri;
                if (index > 0)
                {
                    uri = uriSpan.Slice(0, index).ToString();
                }
                if (jT808MsgIdHttpHandlerBase.HandlerDict.TryGetValue(uri, out var funcHandler))
                {
                    jT808HttpResponse = funcHandler(new JT808HttpRequest()
                    {
                        Json = msg.Content.ToString(Encoding.UTF8)
                    });
                }
                else
                {
                    jT808HttpResponse = jT808MsgIdHttpHandlerBase.NotFoundHttpResponse();
                }
            }
            if (jT808HttpResponse != null)
            {
                WriteResponse(ctx, Unpooled.WrappedBuffer(jT808HttpResponse.Data), TypeJson, jT808HttpResponse.Data.Length);
            }
        }