TestProxyBMPClient.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:browsermob-proxy-client 作者:
@Test
public void testOverridesResponseAsResponseFilter() 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>");
    BMPResponseFilter bmpResponseFilter = new BMPResponseFilter(responseOverrides, contents, null);
    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);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号