File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
browsermob-core-littleproxy/src
main/java/net/lightbody/bmp/filters
test/groovy/net/lightbody/bmp/proxy Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 33import io .netty .channel .ChannelHandlerContext ;
44import io .netty .handler .codec .http .DefaultFullHttpResponse ;
55import io .netty .handler .codec .http .HttpHeaders ;
6+ import io .netty .handler .codec .http .HttpMethod ;
67import io .netty .handler .codec .http .HttpObject ;
78import io .netty .handler .codec .http .HttpRequest ;
89import io .netty .handler .codec .http .HttpResponse ;
@@ -37,6 +38,11 @@ public HttpResponse clientToProxyRequest(HttpObject httpObject) {
3738 String url = getFullUrl (httpRequest );
3839
3940 for (BlacklistEntry entry : blacklistedUrls ) {
41+ if (HttpMethod .CONNECT .equals (httpRequest .getMethod ()) && entry .getHttpMethodPatern () == null ) {
42+ // do not allow CONNECTs to be blacklisted unless a method pattern is explicitly specified
43+ continue ;
44+ }
45+
4046 if (entry .matches (url , httpRequest .getMethod ().name ())) {
4147 HttpResponseStatus status = HttpResponseStatus .valueOf (entry .getStatusCode ());
4248 HttpResponse resp = new DefaultFullHttpResponse (httpRequest .getProtocolVersion (), status );
Original file line number Diff line number Diff line change @@ -175,4 +175,31 @@ class BlacklistTest extends MockServerTest {
175175 assertThat (" Expected blacklisted response to contain 0-length body" , blacklistedResponseBody, isEmptyOrNullString())
176176 }
177177 }
178+
179+ @Test
180+ void testBlacklistDoesNotApplyToCONNECT () {
181+ mockServer. when(request()
182+ .withMethod(" GET" )
183+ .withPath(" /connectNotBlacklisted" ),
184+ Times . unlimited())
185+ .respond(response()
186+ .withStatusCode(200 )
187+ .withBody(" success" ))
188+
189+ proxy = new BrowserMobProxyServer ()
190+ proxy. setTrustAllServers(true )
191+ proxy. start()
192+ int proxyPort = proxy. getPort()
193+
194+ // HTTP CONNECTs should not be blacklisted unless the method is explicitly specified
195+ proxy. blacklistRequests(" https://localhost:${ mockServerPort} " , 405 )
196+
197+ ProxyServerTest . getNewHttpClient(proxyPort). withCloseable {
198+ CloseableHttpResponse response = it. execute(new HttpGet (" https://localhost:${ mockServerPort} /connectNotBlacklisted" ))
199+ assertEquals (" Expected to receive response from mock server after successful CONNECT" , 200 , response. getStatusLine(). getStatusCode())
200+
201+ String responseBody = IOUtils . toStringAndClose(response. getEntity(). getContent())
202+ assertEquals (" Expected to receive HTTP 200 and success message from server" , " success" , responseBody)
203+ }
204+ }
178205}
You can’t perform that action at this time.
0 commit comments