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 3
3
import io .netty .channel .ChannelHandlerContext ;
4
4
import io .netty .handler .codec .http .DefaultFullHttpResponse ;
5
5
import io .netty .handler .codec .http .HttpHeaders ;
6
+ import io .netty .handler .codec .http .HttpMethod ;
6
7
import io .netty .handler .codec .http .HttpObject ;
7
8
import io .netty .handler .codec .http .HttpRequest ;
8
9
import io .netty .handler .codec .http .HttpResponse ;
@@ -37,6 +38,11 @@ public HttpResponse clientToProxyRequest(HttpObject httpObject) {
37
38
String url = getFullUrl (httpRequest );
38
39
39
40
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
+
40
46
if (entry .matches (url , httpRequest .getMethod ().name ())) {
41
47
HttpResponseStatus status = HttpResponseStatus .valueOf (entry .getStatusCode ());
42
48
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 {
175
175
assertThat (" Expected blacklisted response to contain 0-length body" , blacklistedResponseBody, isEmptyOrNullString())
176
176
}
177
177
}
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
+ }
178
205
}
You can’t perform that action at this time.
0 commit comments