RequestParser { public void parse(RequestImpl request, HttpServerExchange exchange, ActionLog actionLog) throws Throwable { HeaderMap headers = exchange.getRequestHeaders(); request.scheme = scheme(exchange.getRequestScheme(), headers.getFirst(Headers.X_FORWARDED_PROTO)); request.hostName = hostName(exchange.getHostName(), headers.getFirst(Headers.X_FORWARDED_HOST)); int requestPort = requestPort(headers.getFirst(Headers.HOST), request.scheme, exchange); request.port = port(requestPort, headers.getFirst(Headers.X_FORWARDED_PORT)); String method = exchange.getRequestMethod().toString(); actionLog.context("method", method); request.requestURL = requestURL(request, exchange); actionLog.context("request_url", request.requestURL); logHeaders(headers); parseClientIP(request, exchange, actionLog, headers.getFirst(Headers.X_FORWARDED_FOR)); parseCookies(request, exchange); request.method = httpMethod(method); logSiteHeaders(headers, actionLog); parseQueryParams(request, exchange.getQueryParameters()); if (withBodyMethods.contains(request.method)) { String contentType = headers.getFirst(Headers.CONTENT_TYPE); request.contentType = contentType == null ? null : ContentType.parse(contentType); parseBody(request, exchange); actionLog.stats.put("http_content_length", (double) exchange.getRequestContentLength()); } }  void parse(RequestImpl request, HttpServerExchange exchange, ActionLog actionLog); final ClientIPParser clientIPParser; public boolean logSiteHeaders; }
@Test void parse() throws Throwable { byte[] body = Strings.bytes("{}"); var actionLog = new ActionLog(null, null); var exchange = new HttpServerExchange(null); exchange.setRequestMethod(Methods.POST); exchange.getRequestHeaders().put(Headers.HOST, "localhost"); exchange.setDestinationAddress(new InetSocketAddress(80)); exchange.setSourceAddress(new InetSocketAddress(10000)); exchange.getRequestHeaders().put(Headers.CONTENT_LENGTH, body.length); exchange.putAttachment(RequestBodyReader.REQUEST_BODY, new RequestBodyReader.RequestBody(body, null)); var request = new RequestImpl(exchange, null); request.contentType = ContentType.TEXT_XML; parser.parse(request, exchange, actionLog); assertThat(request.method).isEqualTo(HTTPMethod.POST); assertThat(request.body()).hasValue(body); assertThat(actionLog.stats).containsKeys("http_content_length"); }