@Test public void canParsePostFormUrlEncodeRequest() throws RequestParseException { HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(); String reqStr = "POST / HTTP/1.1\r\n" + "Content-Length: 31\r\n"+ "Content-Type: application/x-www-form-urlencoded;charset=utf-8\r\n" + "\r\n" + "title=test&key1=1&key2=2&key3=3"; HttpRequestParser parser = new HttpRequestParser(reqStr.getBytes(), requestBuilder); HttpRequest httpRequest = parser.parse(); Map<String, String> headers = new HashMap<>(); Map<String, String> parameters = new HashMap<>(); parameters.put("title", "test"); parameters.put("key1", "1"); parameters.put("key2", "2"); parameters.put("key3", "3"); headers.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); headers.put("Content-Length", "31"); HttpRequest expect = HttpRequest.newBuilder() .setMethod("POST") .setHttpVersion("HTTP/1.1") .setHeaders(headers) .setPath("/") .setParameters(parameters) .setBody("title=test&key1=1&key2=2&key3=3") .build(); assertEquals(expect, httpRequest); }
public HttpRequest parse() throws RequestParseException { parseRequestLine(); parseHeaders(); parseBody(); return requestBuilder.build(); }
HttpRequestParser { public HttpRequest parse() throws RequestParseException { parseRequestLine(); parseHeaders(); parseBody(); return requestBuilder.build(); } }
HttpRequestParser { public HttpRequest parse() throws RequestParseException { parseRequestLine(); parseHeaders(); parseBody(); return requestBuilder.build(); } HttpRequestParser(byte[] rawRequest, HttpRequest.Builder requestBuilder); }
HttpRequestParser { public HttpRequest parse() throws RequestParseException { parseRequestLine(); parseHeaders(); parseBody(); return requestBuilder.build(); } HttpRequestParser(byte[] rawRequest, HttpRequest.Builder requestBuilder); HttpRequest parse(); }
HttpRequestParser { public HttpRequest parse() throws RequestParseException { parseRequestLine(); parseHeaders(); parseBody(); return requestBuilder.build(); } HttpRequestParser(byte[] rawRequest, HttpRequest.Builder requestBuilder); HttpRequest parse();  }