@Test public void canParseGetWithQueryStringParameters() throws RequestParseException { HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(); String reqStr = "GET /xiantang?org=growingio&year_list=1 HTTP/1.1\r\n" + "Host: github.com\r\n" + "Connection: keep-alive\r\n" + "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36\r\n" + "\r\n"; HttpRequestParser parser = new HttpRequestParser(reqStr.getBytes(), requestBuilder); HttpRequest actual = parser.parse(); Map<String, String> parameters = new HashMap<>(); Map<String, String> headers = new HashMap<>(); headers.put("Host", "github.com"); headers.put("Connection", "keep-alive"); headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"); parameters.put("org", "growingio"); parameters.put("year_list", "1"); HttpRequest expected = HttpRequest.newBuilder() .setMethod("GET") .setHttpVersion("HTTP/1.1") .setHeaders(headers) .setPath("/xiantang") .setParameters(parameters) .build(); assertEquals(expected, actual); }
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();  }