public boolean matches ( Request req ) { if ( ! method . equals ( req . getMethod ( ) ) ) return false ; if ( useRegexForPath ) { if ( ! req . getPath ( ) . getPath ( ) . matches ( basePath ) ) return false ; } else { if ( ! basePath . equals ( req . getPath ( ) . getPath ( ) ) ) return false ; } if ( ! queries . keySet ( ) . containsAll ( req . getQuery ( ) . keySet ( ) ) ) return false ; if ( ! req . getNames ( ) . containsAll ( headers . keySet ( ) ) ) return false ; try { if ( ! isEmpty ( bodyMustContain ) && ! req . getContent ( ) . contains ( bodyMustContain ) ) return false ; } catch ( IOException e ) { return false ; } for ( Map . Entry < String , String > reqQuery : req . getQuery ( ) . entrySet ( ) ) { String respRegex = queries . get ( reqQuery . getKey ( ) ) ; if ( ! reqQuery . getValue ( ) . matches ( respRegex ) ) return false ; } for ( Map . Entry < String , String > header : headers . entrySet ( ) ) { String headerValueRegex = header . getValue ( ) ; if ( ! req . getValue ( header . getKey ( ) ) . matches ( headerValueRegex ) ) return false ; } return true ; }
Checks if HTTP request matches all fields specified in config . Fails on first mismatch . Both headers and query params can be configured as regex .