Skip to content

Commit

Permalink
refactor: 개행 정리 및 불필요한 메서드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
aak2075 committed Sep 4, 2023
1 parent 2b05c7c commit 3069ea7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 27 deletions.
3 changes: 0 additions & 3 deletions tomcat/src/main/java/nextstep/handler/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
import org.apache.coyote.http11.HttpResponse;
import org.apache.coyote.http11.HttpStatus;
import org.apache.coyote.http11.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Handler {

public static final String INDEX_HTML = "/index.html";
private static final Logger log = LoggerFactory.getLogger(Handler.class);
private static final String TEXT_HTML = "text/html;charset=utf-8";

private Handler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class Http11Processor implements Runnable, Processor {

private static final Logger log = LoggerFactory.getLogger(Http11Processor.class);

private final Socket connection;

public Http11Processor(final Socket connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public class HttpHeaders {

private final Map<String, String> headers = new HashMap<>();

public HttpHeaders() {
}

public boolean containsHeader(String headerName) {
return this.headers.containsKey(headerName);
}
Expand Down
8 changes: 0 additions & 8 deletions tomcat/src/main/java/org/apache/coyote/http11/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ public String getId() {
return id;
}

public Object getAttribute(final String name) {
return this.values.get(name);
}

public void setAttribute(final String name, final Object value) {
this.values.put(name, value);
}

public void removeAttribute(final String name) {
this.values.remove(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ private static Map<String, String> parseParameters(String queryString) {

private static String getFilePath(String uri) {
String filePath = uri.split("\\?")[0];
if (!filePath.matches(".+\\.[a-zA-Z]+$")) {
return filePath + ".html";
if (filePath.matches(".+\\.[a-zA-Z]+$") || filePath.equals("/")) {
return filePath;
}
return filePath;
return filePath + ".html";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,17 @@ public static void write(OutputStream outputStream, HttpResponse httpResponse)
}

private static String createOkResponse(HttpResponse httpResponse, String contentType) {
return String.join("\r\n",
createStatusLine(httpResponse),
return String.join("\r\n", createStatusLine(httpResponse) + " ",
String.join(HEADER_DELIMITER, HttpHeaders.CONTENT_TYPE, contentType) + " ",
String.join(HEADER_DELIMITER, HttpHeaders.CONTENT_LENGTH,
String.valueOf(httpResponse.getBody().getBytes().length)) + " ",
"",
String.valueOf(httpResponse.getBody().getBytes().length)) + " ", "",
httpResponse.getBody());
}

private static String createFoundResponse(HttpResponse httpResponse) {
return String.join("\r\n",
createStatusLine(httpResponse) + " ",
setCookie(httpResponse) + " ",
String.join(HEADER_DELIMITER, HttpHeaders.LOCATION, httpResponse.getHeader("Location")) + " ",
"",
httpResponse.getBody());
return String.join("\r\n", createStatusLine(httpResponse) + " ",
setCookie(httpResponse) + " ", String.join(HEADER_DELIMITER, HttpHeaders.LOCATION,
httpResponse.getHeader("Location")) + " ", "", httpResponse.getBody());
}

private static String createStatusLine(HttpResponse httpResponse) {
Expand Down

0 comments on commit 3069ea7

Please sign in to comment.