Skip to content

Commit

Permalink
style: Request 관련 상수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
poi1649 committed Sep 4, 2023
1 parent 025bf5d commit 7485581
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tomcat/src/main/java/org/apache/coyote/http11/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class HttpRequest {
private static final String HEADER_BODY_DELIMITER = "";
private static final String PATH_QUERY_STRING_DELIMITER = "\\?";
private static final String INDEX_HTML = "/index.html";
private static final int URI_INDEX = 0;
private static final int METHOD_INDEX = 0;
private static final int PATH_AND_PARAMETER_INDEX = 1;
private static final int PATH_INDEX = 0;
private static final int QUERY_PARAM_INDEX = 1;


private final HttpMethod method;
private final String path;
Expand All @@ -37,24 +43,24 @@ public static HttpRequest from(final BufferedReader reader) throws IOException {
while ((line = reader.readLine()) != null && !line.isEmpty()) {
request.add(line);
}
request.add(HEADER_BODY_DELIMITER);
final HttpHeaders header = HttpHeaders.createBasicRequestHeadersFrom(request);
final var header = HttpHeaders.createBasicRequestHeadersFrom(request);

request.add(HEADER_BODY_DELIMITER);
if (header.getContentLength() > 0) {
var bodyChars = new char[header.getContentLength()];
reader.read(bodyChars, 0, bodyChars.length);
body = new String(bodyChars);
properties = JsonProperties.from(body.trim(), header);
}

final String[] uri = request.get(0).split(" ");
final var method = HttpMethod.of(uri[0]);
final var fullPath = uri[1];
final String[] uri = request.get(URI_INDEX).split(" ");
final var method = HttpMethod.of(uri[METHOD_INDEX]);
final var fullPath = uri[PATH_AND_PARAMETER_INDEX];

if (fullPath.contains("?")) {
final String[] pathAndQueryParams = fullPath.split(PATH_QUERY_STRING_DELIMITER);
final var path = pathAndQueryParams[0].trim();
final var queryStrings = new QueryStrings(pathAndQueryParams[1].trim());
final var path = pathAndQueryParams[PATH_INDEX].trim();
final var queryStrings = new QueryStrings(pathAndQueryParams[QUERY_PARAM_INDEX].trim());
return new HttpRequest(method, path, header, queryStrings, body, properties);
}

Expand Down

0 comments on commit 7485581

Please sign in to comment.