Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Once that is done, a new proxy will be available on the port returned. All you h
- PUT /proxy/[port]/blacklist - Set a URL to blacklist. Takes the following parameters:
- regex - the blacklist regular expression
- status - the HTTP status code to return for URLs that are blacklisted
- method - regular expression for matching method., e.g., POST. Emtpy for matching all method.
- DELETE /proxy/[port]/blacklist - Clears all URL patterns from the blacklist
- PUT /proxy/[port]/limit - Limit the bandwidth through the proxy. Takes the following parameters:
- downstreamKbps - Sets the downstream kbps
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/lightbody/bmp/proxy/BlacklistEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ public class BlacklistEntry
{
private Pattern pattern;
private int responseCode;
private Pattern method;

public BlacklistEntry(String pattern, int responseCode) {
public BlacklistEntry(String pattern, int responseCode, String method) {
this.pattern = Pattern.compile(pattern);
this.responseCode = responseCode;
this.method = Pattern.compile(("".equals(method) || method == null) ? ".*" : method);
}

public Pattern getPattern() {
Expand All @@ -19,4 +21,8 @@ public Pattern getPattern() {
public int getResponseCode() {
return this.responseCode;
}

public Pattern getMethod() {
return this.method;
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/lightbody/bmp/proxy/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ public void clearRewriteRules() {
client.clearRewriteRules();
}

public void blacklistRequests(String pattern, int responseCode) {
client.blacklistRequests(pattern, responseCode);
public void blacklistRequests(String pattern, int responseCode, String method) {
client.blacklistRequests(pattern, responseCode, method);
}

public List<BlacklistEntry> getBlacklistedRequests() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public Reply<?> blacklist(@Named("port") int port, Request request) {

String blacklist = request.param("regex");
int responseCode = parseResponseCode(request.param("status"));
proxy.blacklistRequests(blacklist, responseCode);
String method = request.param("method");
proxy.blacklistRequests(blacklist, responseCode, method);

return Reply.saying().ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ private BrowserMobHttpResponse execute(BrowserMobHttpRequest req, int depth) {

if (blacklistEntries != null) {
for (BlacklistEntry blacklistEntry : blacklistEntries) {
if (blacklistEntry.getPattern().matcher(url).matches()) {
if (blacklistEntry.getPattern().matcher(url).matches()
&& blacklistEntry.getMethod().matcher(method.getMethod()).matches()) {
mockResponseCode = blacklistEntry.getResponseCode();
break;
}
Expand Down Expand Up @@ -1196,12 +1197,12 @@ public void clearRewriteRules() {

// this method is provided for backwards compatibility before we renamed it to
// blacklistRequests (note the plural)
public void blacklistRequest(String pattern, int responseCode) {
blacklistRequests(pattern, responseCode);
public void blacklistRequest(String pattern, int responseCode, String method) {
blacklistRequests(pattern, responseCode, method);
}

public void blacklistRequests(String pattern, int responseCode) {
blacklistEntries.add(new BlacklistEntry(pattern, responseCode));
public void blacklistRequests(String pattern, int responseCode, String method) {
blacklistEntries.add(new BlacklistEntry(pattern, responseCode, method));
}

public List<BlacklistEntry> getBlacklistedRequests() {
Expand Down