Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1 -2단계 - Tomcat 구현하기] 릴리(최윤서) 미션 제출합니다. #528

Merged
merged 14 commits into from
Sep 11, 2024

Conversation

lilychoibb
Copy link
Member

@lilychoibb lilychoibb commented Sep 6, 2024

안녕하세요 몰리!~ ⍢

코드리뷰 잘 부탁드려요 :)
리뷰 하시다가 궁금한 점 있으시면 언제든 DM 주셔도 좋아요 🤗

Copy link

@jminkkk jminkkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 릴리 🙌
코드가 전반적으로 깔끔해서 잘 이해할 수 있었어요!

리뷰 남겨보았으니 확인 부탁드립니다 🍀
(릴리의 의도와 다른 부분이나 제가 잘못 이해한 부분이 있다면 편하게 말해주세요 😀)

Copy link

@jminkkk jminkkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 릴리 🙌
리뷰 잘 반영해주셨네요!

코멘트 조금 남겨두었으니, 확인 부탁드립니다 🍀

@@ -0,0 +1,4 @@
package org.apache.coyote.http;

public record StatusCode(String statusCode) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StatusCode를 enum이 아닌 record 타입으로 선언한 이유가 궁금해요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VO 와 순간 헷갈렸던 것 같아요 😅 수정했습니다!

@@ -0,0 +1,4 @@
package org.apache.coyote.http;

public record HttpVersion(String version) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 마찬가지로 enum은 어떨까요?

}

@Override
public void add(Session session) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

몇몇 메서드 인자에 final 키워드가 사용되고 있는데, 통일이 필요할 것 같아요 🥲

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

통일하겠습니다🙂!

Comment on lines +57 to +72
StringBuilder responseBuilder = new StringBuilder();

responseBuilder.append(httpVersion.version()).append(" ")
.append(statusCode.statusCode()).append(" ").append("\r\n");

for (Map.Entry<String, String> header : headers.entrySet()) {
responseBuilder.append(header.getKey()).append(": ").append(header.getValue()).append(" ").append("\r\n");
}

responseBuilder.append("\r\n");

if (responseBody != null && !responseBody.isEmpty()) {
responseBuilder.append(responseBody);
}

return responseBuilder.toString().getBytes(StandardCharsets.UTF_8);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
StringBuilder responseBuilder = new StringBuilder();
responseBuilder.append(httpVersion.version()).append(" ")
.append(statusCode.statusCode()).append(" ").append("\r\n");
for (Map.Entry<String, String> header : headers.entrySet()) {
responseBuilder.append(header.getKey()).append(": ").append(header.getValue()).append(" ").append("\r\n");
}
responseBuilder.append("\r\n");
if (responseBody != null && !responseBody.isEmpty()) {
responseBuilder.append(responseBody);
}
return responseBuilder.toString().getBytes(StandardCharsets.UTF_8);
appendStatusLine(httpVersion, statusCode, statusMessage);
appendHeaders(headers);
appendBody(responseBody);
return responseBuilder.toString().getBytes(StandardCharsets.UTF_8);

메서드로 추출해보면 어떨까요?

Comment on lines +54 to +65
private String getContentType(String resource) {
if (resource.endsWith(".css")) {
return "text/css";
} else if (resource.endsWith(".js")) {
return "application/javascript";
} else if (resource.endsWith(".ico")) {
return "image/x-icon";
} else if (resource.endsWith(".html")) {
return "text/html";
} else {
return "text/plain";
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 MimeTypesFileTypeMap 라는 클래스 사용을 고민해봐도 좋을 것 같아요 !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구두논의 후 Files.probeContentType 사용

Comment on lines +85 to +91
private String getParameter(String requestBody, String key) {
return Arrays.stream(requestBody.split("&"))
.filter(param -> param.startsWith(key + "="))
.map(param -> param.split("=")[1])
.findFirst()
.orElse("");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content-typeapplication/x-www-form-urlencoded 인 경우 Body의 형태가 key value 쌍으로 온다고 하더라구요!
따라서 key value 파싱 또한 현재 컨트롤러가 아닌 Request 파싱 단계에서 이루어져야 할 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request 에서 처리하도록 변경하였습니다!

Comment on lines +46 to +51
handleSuccessfulLogin(response, account);
}

if (!findUserByInfo(account, password)) {
handleFailedLogin(response);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
handleSuccessfulLogin(response, account);
}
if (!findUserByInfo(account, password)) {
handleFailedLogin(response);
}
handleSuccessfulLogin(response, account);
return;
}
handleFailedLogin(response);

early return을 해보면 불필요한 조건문을 제거할 수 있을 것 같아요!

@@ -0,0 +1,24 @@
package com.techcourse.controller;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/com.techcourse.controller 에 위치해 있는데, 이 클래스는 해당 서비스가 다뤄야할 부분은 아닌 것 같다는 생각이 들어요
현재 패키지 구조에서 /com/techcourse/에는 해당 애플리케이션의 고유한 비즈니스 플로우가 담겨야 할 것 같다는 생각인데요, 🤔

릴리는 어떻게 생각하시는지 궁금합니당

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 같은 생각입니다!
/org.apache.catalina.controller 에 두었습니다

@@ -1,14 +1,13 @@
package org.apache.coyote.http11;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test를 추가해볼까요?
모든 도메인에 대한 단위테스트까진 아니더라도 통합 테스트라도 작성해보면 어떨까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 작성 하겠습니다 :) 👍

Copy link

@jminkkk jminkkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment 는 알람이 안 가나봐요 ㅠㅠ
이번 pr은 충분히 만족한 것 같아서 approve 하겠습니다!
다음 단계 pr에 리뷰 반영해주시면 좋을 것 같아요!

@jminkkk jminkkk merged commit 4c0f3a1 into woowacourse:lilychoibb Sep 11, 2024
@lilychoibb lilychoibb deleted the step1 branch September 12, 2024 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants