/** * Returns an {@code OperationPreprocessor} that will remove any headers from the * request or response with a name that matches one of the given * {@code headerNamePatterns} regular expressions. * @param headerNamePatterns the header name patterns * @return the preprocessor * @see java.util.regex.Matcher#matches() */ public static OperationPreprocessor removeMatchingHeaders( String... headerNamePatterns) { return new HeaderRemovingOperationPreprocessor( new PatternMatchHeaderFilter(headerNamePatterns)); }
/** * Returns an {@code OperationPreprocessor} that will remove any header from the * request or response with a name that is equal to one of the given * {@code headersToRemove}. * @param headerNames the header names * @return the preprocessor * @see String#equals(Object) */ public static OperationPreprocessor removeHeaders(String... headerNames) { return new HeaderRemovingOperationPreprocessor( new ExactMatchHeaderFilter(headerNames)); }
@Test public void modifyWithPattern() { OperationResponse response = createResponse("content-length", "1234"); HeaderRemovingOperationPreprocessor processor = new HeaderRemovingOperationPreprocessor( new PatternMatchHeaderFilter("co.*le(.)gth]")); OperationResponse preprocessed = processor.preprocess(response); assertThat(preprocessed.getHeaders().size()).isEqualTo(2); assertThat(preprocessed.getHeaders()).containsEntry("a", Arrays.asList("alpha")); assertThat(preprocessed.getHeaders()).containsEntry("b", Arrays.asList("bravo", "banana")); }
@Test public void removeAllHeaders() { HeaderRemovingOperationPreprocessor processor = new HeaderRemovingOperationPreprocessor( new PatternMatchHeaderFilter(".*")); OperationResponse preprocessed = processor.preprocess(createResponse()); assertThat(preprocessed.getHeaders().size()).isEqualTo(0); }