@Test
public void testOverridesResponseAsResponseFilterAndListUrl() throws Throwable {
Headers headersExpected = new Headers();
List<String> accessControlAllowCredentialsList = new ArrayList<>();
accessControlAllowCredentialsList.add("test");
accessControlAllowCredentialsList.add("test2");
headersExpected.put(ACCESS_CONTROL_ALLOW_CREDENTIALS, accessControlAllowCredentialsList);
List<String> accessControlMaxAgeList = new ArrayList<>();
accessControlMaxAgeList.add("test3");
headersExpected.put(ACCESS_CONTROL_MAX_AGE, accessControlMaxAgeList);
io.netty.handler.codec.http.HttpResponse responseOverrides = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.FORBIDDEN);
for (String headers : headersExpected.keySet()) {
for (String headersValue : headersExpected.get(headers)) {
responseOverrides.headers().add(headers, headersValue);
}
}
HttpMessageContents contents = new HttpMessageContents(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.FORBIDDEN));
contents.setTextContents("<html><body>Response successfully intercepted</body></html>");
List<FilterUrls> filterUrls = new ArrayList<>();
filterUrls.add(new FilterUrls("(.*)index\\.html(.*)"));
filterUrls.add(new FilterUrls("^http:\\/\\/search\\.maven\\.org\\/$", HttpMethod.GET));
filterUrls.add(new FilterUrls("(.*)test\\.html(.*)", HttpMethod.POST));
BMPResponseFilter bmpResponseFilter = new BMPResponseFilter(responseOverrides, contents, null, filterUrls);
getBmpLittleProxy().setFilterResponse(bmpResponseFilter);
Unirest.setProxy(new HttpHost(getBmpLittleProxy().getAddress(), getBmpLittleProxy().getPort()));
HttpResponse<String> response = Unirest.get(URL_PROTOCOL + URL_FOR_TEST).asString();
assertOverrideResponseEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.post(URL_PROTOCOL + URL_FOR_TEST).asString();
assertOverrideResponseNotEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.get("http://search.maven.org/index.html").asString();
assertOverrideResponseEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.post("http://search.maven.org/index.html").asString();
assertOverrideResponseEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.get("http://search.maven.org/test.html").asString();
assertOverrideResponseNotEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.post("http://search.maven.org/test.html").asString();
assertOverrideResponseEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.get("http://search.maven.org/abracadabra.alibaba").asString();
assertOverrideResponseNotEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
response = Unirest.post("http://search.maven.org/abracadabra.alibaba").asString();
assertOverrideResponseNotEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
}
TestProxyBMPClient.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:browsermob-proxy-client
作者:
评论列表
文章目录