예제 #1
0
        public bool Match(Session oSession, bool isRequest)
        {
            bool isMatch = true;

            if (UriMatch != null)
            {
                if (!UriMatch.Match(oSession.fullUrl))
                {
                    return(false);
                }
            }
            if (HeadMatch != null)
            {
                if (!HeadMatch.Match(isRequest ? (HTTPHeaders)oSession.RequestHeaders : (HTTPHeaders)oSession.ResponseHeaders))
                {
                    return(false);
                }
            }
            if (BodyMatch != null)
            {
                if (!BodyMatch.Match(isRequest?oSession.GetRequestBodyAsString():oSession.GetResponseBodyAsString()))
                {
                    return(false);
                }
            }
            return(isMatch);
        }
예제 #2
0
        public bool Match(Session oSession, bool isRequest, WebSocketMessage webSocketMessage = null)
        {
            bool isWebSocket = webSocketMessage != null;// oSession.BitFlags.HasFlag(SessionFlags.IsWebSocketTunnel);
            bool isMatch     = true;

            if (isWebSocket)
            {
                if (!oSession.BitFlags.HasFlag(SessionFlags.IsWebSocketTunnel))
                {
                    return(false);
                }
                if (!((isRequest && webSocketMessage.IsOutbound) || (!isRequest && !webSocketMessage.IsOutbound)))
                {
                    return(false);
                }
                if (!UriMatch.Match(oSession.fullUrl))
                {
                    return(false);
                }
                if (BodyMatch != null)
                {
                    if (webSocketMessage.FrameType == WebSocketFrameTypes.Binary && BodyMatch.IsHexMatch)
                    {
                        if (!BodyMatch.Match(webSocketMessage.PayloadAsBytes()))
                        {
                            return(false);
                        }
                    }
                    else if (webSocketMessage.FrameType == WebSocketFrameTypes.Text && !BodyMatch.IsHexMatch)
                    {
                        if (!BodyMatch.Match(webSocketMessage.PayloadAsString()))
                        {
                            return(false);
                        }
                    }
                    else if (webSocketMessage.FrameType == WebSocketFrameTypes.Continuation)
                    {
                        //延续帧
                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (UriMatch != null)
                {
                    if (!UriMatch.Match(oSession.fullUrl))
                    {
                        return(false);
                    }
                }
                if (HeadMatch != null)
                {
                    if (!HeadMatch.Match(true ? (HTTPHeaders)oSession.RequestHeaders : (HTTPHeaders)oSession.ResponseHeaders))
                    {
                        return(false);
                    }
                }
                if (BodyMatch != null)
                {
                    if (BodyMatch.IsHexMatch)
                    {
                        if (!BodyMatch.Match(true ? oSession.requestBodyBytes : oSession.responseBodyBytes))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!BodyMatch.Match(true ? oSession.GetRequestBodyAsString() : oSession.GetResponseBodyAsString()))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(isMatch);
        }