Source:
<code>public void handleRequest(HttpServerExchange httpServerExchange) throws Exception { if (httpServerExchange.isInIoThread()) { httpServerExchange.dispatch(this); return; } Matcher matcher = INFLUX_URI_PATTERN.matcher(httpServerExchange.getRequestURI()); if (!matcher.matches()) { next.handleRequest(httpServerExchange); return; <START> } <END> HeaderMap requestHeaders = httpServerExchange.getRequestHeaders(); String databaseName = matcher.group(1); if (!UUID_PATTERN.matcher(databaseName).matches()) { httpServerExchange.setStatusCode(400); httpServerExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); httpServerExchange.getResponseSender().send("Database name is not a valid identifier.", UTF_8); return; } requestHeaders.put(PERSONA_HEADER, databaseName); Map<String, Deque<String>> requestParameters = httpServerExchange.getQueryParameters(); Deque<String> usernameParamValues = requestParameters.get(USERNAME_PARAM_NAME); Deque<String> passwordParamValues = requestParameters.get(PASSWORD_PARAM_NAME); if (usernameParamValues != null && passwordParamValues != null) { String concat = usernameParamValues.getFirst() + ":" + passwordParamValues.getFirst(); String encoded = Base64.getEncoder().encodeToString(concat.getBytes(UTF_8)); String authHeader = "Basic " + encoded; requestHeaders.put(Headers.AUTHORIZATION, authHeader); httpServerExchange.getQueryParameters().remove(USERNAME_PARAM_NAME); httpServerExchange.getQueryParameters().remove(PASSWORD_PARAM_NAME); } next.handleRequest(httpServerExchange); }</code><technical_language>regex is meant replace this try/catch. case matches regex is spec-compliant. In case, Accounts throw a RuntimeException, so, a matter of taste :)</technical_language>

Target:
public void handleRequest(HttpServerExchange httpServerExchange) throws Exception { if (httpServerExchange.isInIoThread()) { httpServerExchange.dispatch(this); return; } Matcher matcher = INFLUX_URI_PATTERN.matcher(httpServerExchange.getRequestURI()); if (!matcher.matches()) { next.handleRequest(httpServerExchange); return; } HeaderMap requestHeaders = httpServerExchange.getRequestHeaders(); String databaseName = matcher.group(1); try { UUID.fromString(databaseName); } catch (IllegalArgumentException e) { httpServerExchange.setStatusCode(400); httpServerExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); httpServerExchange.getResponseSender().send("Database name is not a valid identifier.", UTF_8); return; } requestHeaders.put(PERSONA_HEADER, databaseName); Map<String, Deque<String>> requestParameters = httpServerExchange.getQueryParameters(); Deque<String> usernameParamValues = requestParameters.get(USERNAME_PARAM_NAME); Deque<String> passwordParamValues = requestParameters.get(PASSWORD_PARAM_NAME); if (usernameParamValues != null && passwordParamValues != null) { String concat = usernameParamValues.getFirst() + ":" + passwordParamValues.getFirst(); String encoded = Base64.getEncoder().encodeToString(concat.getBytes(UTF_8)); String authHeader = "Basic " + encoded; requestHeaders.put(Headers.AUTHORIZATION, authHeader); httpServerExchange.getQueryParameters().remove(USERNAME_PARAM_NAME); httpServerExchange.getQueryParameters().remove(PASSWORD_PARAM_NAME); } next.handleRequest(httpServerExchange); }