RequestParser { String requestURL(RequestImpl request, HttpServerExchange exchange) { var builder = new StringBuilder(128); if (exchange.isHostIncludedInRequestURI()) { builder.append(exchange.getRequestURI()); } else { String scheme = request.scheme; int port = request.port; builder.append(scheme) .append(": .append(request.hostName); if (!(port == 80 && "http".equals(scheme)) && !(port == 443 && "https".equals(scheme))) { builder.append(':').append(port); } builder.append(exchange.getRequestURI()); } String queryString = exchange.getQueryString(); if (!queryString.isEmpty()) builder.append('?').append(queryString); String requestURL = builder.toString(); if (requestURL.length() > MAX_URL_LENGTH) throw new BadRequestException(format("requestURL is too long, requestURL={}...(truncated)", requestURL.substring(0, 50)), "INVALID_HTTP_REQUEST"); return requestURL; }  void parse(RequestImpl request, HttpServerExchange exchange, ActionLog actionLog); final ClientIPParser clientIPParser; public boolean logSiteHeaders; }
@Test void requestURL() { var exchange = new HttpServerExchange(null); exchange.setRequestURI("/path"); exchange.setQueryString("key=value"); var request = new RequestImpl(exchange, null); request.scheme = "https"; request.hostName = "localhost"; request.port = 443; assertThat(parser.requestURL(request, exchange)) .isEqualTo("https: }
@Test void requestURLIsTooLong() { var exchange = new HttpServerExchange(null); exchange.getRequestHeaders().put(Headers.HOST, "localhost"); exchange.setRequestURI("/path"); exchange.setQueryString("1234567890".repeat(100)); var request = new RequestImpl(exchange, null); request.scheme = "http"; request.port = 80; assertThatThrownBy(() -> parser.requestURL(request, exchange)) .isInstanceOf(BadRequestException.class) .hasMessageContaining("requestURL is too long"); }