RequestParser { void parseQueryParams(RequestImpl request, Map<String, Deque<String>> params) { for (Map.Entry<String, Deque<String>> entry : params.entrySet()) { String key = entry.getKey(); String value = entry.getValue().getFirst(); try { String paramName = decode(key, UTF_8); String paramValue = decode(value, UTF_8); logger.debug("[request:query] {}={}", paramName, paramValue); request.queryParams.put(paramName, paramValue); } catch (IllegalArgumentException e) { throw new BadRequestException(format("failed to parse query param, name={}, value={}", key, value), "INVALID_HTTP_REQUEST", e); } } }  void parse(RequestImpl request, HttpServerExchange exchange, ActionLog actionLog); final ClientIPParser clientIPParser; public boolean logSiteHeaders; }
@Test void parseQueryParams() { var request = new RequestImpl(null, null); Map<String, Deque<String>> params = Map.of("key", new ArrayDeque<>(List.of(encode("value1 value2", UTF_8))), "emptyKey", new ArrayDeque<>(List.of(""))); parser.parseQueryParams(request, params); assertThat(request.queryParams()).containsOnly(entry("key", "value1 value2"), entry("emptyKey", "")); }
@Test void parseQueryParamsWithInvalidValue() { var request = new RequestImpl(null, null); Map<String, Deque<String>> params = Map.of("cd+/tmp;cd+/var;wget+http: assertThatThrownBy(() -> parser.parseQueryParams(request, params)) .isInstanceOf(BadRequestException.class) .hasMessageContaining("failed to parse query param"); }