ExpansionHandler implements RuleChangesObserver { public boolean isZipRequest(HttpServerRequest request) { boolean ok = false; if (HttpMethod.GET == request.method() && request.params().contains(ZIP_PARAM)) { ok = ! request.params().get(ZIP_PARAM).equalsIgnoreCase("false"); } return ok && !isBackendExpand(request.uri()); } ExpansionHandler(Vertx vertx, final ResourceStorage storage, HttpClient httpClient, final Map<String, Object> properties, String serverRoot, final String rulesPath); @Override void rulesChanged(List<Rule> rules); int getMaxExpansionLevelSoft(); int getMaxExpansionLevelHard(); int getMaxSubRequestCount(); boolean isExpansionRequest(HttpServerRequest request); boolean isZipRequest(HttpServerRequest request); void handleExpansionRecursion(final HttpServerRequest request); void handleZipRecursion(final HttpServerRequest request); boolean isCollection(String target); static final String SERIOUS_EXCEPTION; static final String EXPAND_PARAM; static final String ZIP_PARAM; static final String MAX_EXPANSION_LEVEL_SOFT_PROPERTY; static final String MAX_EXPANSION_LEVEL_HARD_PROPERTY; static final String MAX_SUBREQUEST_PROPERTY; }
@Test public void testIsZipRequest(TestContext context) { expansionHandler = new ExpansionHandler(vertx, storage, httpClient, new HashMap<>(), ROOT, RULES_ROOT); CaseInsensitiveHeaders params = new CaseInsensitiveHeaders(); params.set(ZIP_PARAM, "true"); context.assertFalse(expansionHandler.isZipRequest(new Request(HttpMethod.PUT, "/some/uri", params)), "PUT requests should not be zip requests"); context.assertTrue(expansionHandler.isZipRequest(new Request(HttpMethod.GET, "/some/uri", params)), "GET request with correct params and not configured as expandOnBackend should be zip requests"); params.set(ZIP_PARAM, "false"); context.assertFalse(expansionHandler.isZipRequest(new Request(HttpMethod.GET, "/some/uri", params)), "GET request with correct params (value=false) and not configured as expandOnBackend should not be zip requests"); params.set(ZIP_PARAM, "foobar"); context.assertTrue(expansionHandler.isZipRequest(new Request(HttpMethod.GET, "/some/uri", params)), "GET request with correct params (value != false) and not configured as expandOnBackend should be zip requests"); context.assertFalse(expansionHandler.isZipRequest(new Request(HttpMethod.GET, "/some/uri", new CaseInsensitiveHeaders())), "GET requests without correct params should not be zip requests"); List<Rule> rules = new ArrayList<>(); Rule rule1 = new Rule(); rule1.setUrlPattern("/some/backendExpand/uri"); rule1.setExpandOnBackend(true); rules.add(rule1); expansionHandler.rulesChanged(rules); params.set(ZIP_PARAM, "true"); context.assertFalse(expansionHandler.isZipRequest(new Request(HttpMethod.GET, "/some/backendExpand/uri", params)), "GET request with correct params and configured as expandOnBackend should not be zip requests"); }