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

[톰캣 구현하기 - 3, 4단계] 저문(유정훈) 미션 제출합니다. #459

Merged
merged 15 commits into from
Sep 14, 2023

Conversation

jeomxon
Copy link

@jeomxon jeomxon commented Sep 10, 2023

안녕하세요 조이, 저문입니다 :)
이전에 남겨주신 리뷰를 통해서 많이 배웠습니다!
지난 리뷰에 대한 답변은 여기에 남겨두었습니다.

이번은 3단계 리팩터링을 진행하는데 꽤나 오랜시간이 걸렸던 것 같아요.
4단계는 아직 공부해야할 내용이 산더미네요..ㅎㅎ

크게 변한건 없지만 Controller가 생기면서 로직이 훨씬 알아보기 편해진 것 같아요.
그만큼 조이가 리뷰하시기 수월했으면 하네요.

리뷰 잘 부탁드립니다🙇🏻‍♂️🙇🏻‍♂️🙇🏻‍♂️

@jeomxon jeomxon assigned jeomxon and unassigned jeomxon Sep 10, 2023
Copy link
Member

@yeonkkk yeonkkk left a comment

Choose a reason for hiding this comment

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

안녕하세요 저문! 조이입니다🍀

이번에도 구현을 정말 잘 해주셨네요..
코드가 너무 깔끔해서 리뷰하기도 너무 편했고, 정말 많이 배웠습니다🙂
남길 코멘트가 거의 컨벤션 관련된 것 뿐이네요 ㅎㅎ 역시 고수,,👀⭐️

지난 PR과 이번 PR에 모두 코멘트 남겨두었으니, 편하실 때 확인 부탁드려요 ㅎㅎ
고생하셨습니다!

Comment on lines 29 to 33
@Override
protected void doGet(final HttpRequest request, final HttpResponse response) {
response.setHttpStatus(HttpStatus.OK);
response.setPath(REGISTER_PAGE);
}
Copy link
Member

Choose a reason for hiding this comment

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

요구사항은 아니지만, 로그인한 상태로 /register 를 누르면 회원가입 창으로 가네요!
로그인한 사용자 입장에서 조금 부자연스러울수도 있을 것 같아요🧐

저문은 어떻게 생각하시나요?

Copy link
Author

Choose a reason for hiding this comment

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

당연히 막아야하는 부분이라는 생각이 드는데 제가 인지하지 못했네요.
수정하겠습니다!

import java.util.Map;
import org.apache.coyote.http11.request.HttpRequest;

public class RequestMapping {
Copy link
Member

Choose a reason for hiding this comment

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

사용자 입장에서 /jeomxon/login, /jeomxon/register, /index.htm 등 정의하지 않은 URI에 접근하면 404.html 화면을 보여주는게 보다 자연스러울 것 같아요!
저문은 어떻게 생각하시나요?!

Copy link
Author

Choose a reason for hiding this comment

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

사용자가 어떤 행동을 할지 예측할 수 없으니 좋은 것 같아요
반영했습니다!


public class HttpResponseHeader {

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

Choose a reason for hiding this comment

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

Map<String, String> headers 가 사용되지 않고 있네요.
사용하지 않는데 제거하지 않은 이유가 있나요?🤔

(아마 사용하지 않고 있는 이유는 response header들을 response에서 넣어줘서 그런 것 같네요?!)

Copy link
Author

Choose a reason for hiding this comment

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

제거하는 방향으로 변경했습니다!

return makeRedirectResponse();
}

final URL resource = HttpResponse.class.getClassLoader().getResource("static" + path);
Copy link
Member

Choose a reason for hiding this comment

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

"static" 도 상수화해주면 어떨까요?


public String get() throws IOException {
final String contentType = ContentType.getByPath(path) + CHARSET_UTF_8;
if (path.equals("/")) {
Copy link
Member

Choose a reason for hiding this comment

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

"/" 도 상수화하면 의미하는 바가 명확해질 것 같아요!

Comment on lines 52 to 54
if (session == null) {
throw new IllegalArgumentException("존재하지 않는 세션입니다.");
}
Copy link
Member

Choose a reason for hiding this comment

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

메서드로 분리해서 의미를 명확하게 하면 어떨까요? (depth도 줄어서 좋을 것 같아요 ㅎㅎ)

Copy link
Author

Choose a reason for hiding this comment

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

좋은 것 같아요 분리하겠습니다~

return;
}
response.setHttpStatus(HttpStatus.FOUND);
response.sendRedirect("/404.html");
Copy link
Member

Choose a reason for hiding this comment

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

"/404.html" 이 것도 상수처리 해주면 좋을 것 같네용🥹

@@ -0,0 +1,62 @@
package org.apache.coyote.http11.controller;
Copy link
Member

Choose a reason for hiding this comment

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

변경을 요청드리기보다는 의견을 여쭤보고 싶은 부분인데요, 혹시 controller의 위치(패키지)에 대해 고민해보신 부분이 있으실까요?
(그냥 궁금해서 드리는 질문입니다ㅎ)

Copy link
Author

Choose a reason for hiding this comment

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

따로 공부해보지 않았는데 어떤 키워드로 학습하면 좋을까요?
어떤 의존관계를 가지고 설계해야할지 감이 잘 안잡히네요

Copy link
Member

Choose a reason for hiding this comment

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

저는 tomcat 의 coyote, caltalina 의 역할을 고려하셨는지 궁금해서 여쭤봤어요! ㅎㅎ

}

final URL resource = HttpResponse.class.getClassLoader().getResource("static" + path);
this.body = new String(Files.readAllBytes(new File(resource.getFile()).toPath()));
Copy link
Member

Choose a reason for hiding this comment

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

resource.getFile() 부분에서 파일이 없을 경우 NPE가 발생할 수 있을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

그렇네요.
수정했습니다!

Comment on lines 11 to 12
public SessionManager() {
}
Copy link
Member

Choose a reason for hiding this comment

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

혹시 기본 생성자를 작성해주신 이유가 있을까요?!

Copy link
Author

Choose a reason for hiding this comment

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

이유 없습니다. 삭제했습니다.

@sonarcloud
Copy link

sonarcloud bot commented Sep 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.20.1) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

Copy link
Member

@yeonkkk yeonkkk left a comment

Choose a reason for hiding this comment

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

저문, 조이 입니다!

질문에 답변도 다 해주시고, 리뷰 잘 반영해주신 것도 확인했습니다 ㅎㅎ👍
정말 처음부터 끝까지 코드가 깔끔해서 리뷰하기 너무 너무 편했습니다.
마지막까지 최고네여 ~~

저문의 코드를 리뷰할 수 있어서 너무 영광이었어요 ~~✨
이제 approve & merge 하겠습니다.
고생하셨습니다 ~

@@ -0,0 +1,62 @@
package org.apache.coyote.http11.controller;
Copy link
Member

Choose a reason for hiding this comment

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

저는 tomcat 의 coyote, caltalina 의 역할을 고려하셨는지 궁금해서 여쭤봤어요! ㅎㅎ

return Arrays.stream(body.split("&"))
.map(info -> Arrays.asList(info.split("=")))
return Arrays.stream(body.split(USER_INFO_DELIMITER))
.map(info -> Arrays.asList(info.split(USER_INFO_SEPARATOR)))
.collect(Collectors.toMap(infos -> infos.get(0), infos -> infos.get(1), (a, b) -> b));
Copy link
Member

Choose a reason for hiding this comment

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

상수 네이밍에 소요되는 시간이 많다는 것에 공감합니다..🥲
저는 개인적으로 정말 불필요하다고 생각되는 경우를 제외하고 가급적이면 상수화를 하는 편이긴 합니다.
(모든 경우에 하지는 않습니다)

이건 제가 상수화를 하는 목적과 관계가 있는데요, 제가 생각하는 상수화의 목적은 이렇습니다.

  1. 수정 상황이 발생하는 경우 고려

여러 번 사용되는 값을 상수화 하면, 이후에 값을 변경해야 하는 상황이 오면 상수 처리한 값만 변경하면 되기 때문에 더 효율적이고, 수정하면서 발생할 수 있는 실수(오타 등)을 줄일 수 있습니다.

  1. 다른 개발자가 코드를 볼 때, 코드만으로 이해할 수 있도록 하기 위함 (가독성)

단순 문자, 숫자가 아니라 네이밍을 한 상수로 코드를 작성하면 코드를 처음 보는 사람의 이해도를 높일 수 있다고 생각합니다.
이해도도 높이고 보는 사람의 시간도 절약할 수 있겠네요.
(협업의 관점에서 보면 설명하는 시간도 줄수도 있겠어여 ~)

저문의 말대로 코드를 보는 사람은 대부분 개발자이고 map이 key-value를 대부분 알겠죠🤔 그런데 모두가 그렇다고 확신할 수 있나요?
그리고 (코드 작성자는 당연히 알고 있겠지만) 위 코드를 보고 key-value라고 생각할 수 있으려면 body, info의 구조를 알고 있어야할 것 같아요. 하지만 이름으로 명시해주면 굳이 구조를 확인하지 않아도 key-value 구조라고 생각할수도 있을 것 같아요.

상수화를 하는게 저문 말대로 네이밍하는데 시간도 걸리고 꼭 필요한 작업은 아니기 때문에 선택적인 부분이라고 생각해요!
제 상수화의 기준을 물어봐주시니, 저도 정리하는 시간을 가지게 돼서 좋네요 ㅎㅎ 감사해용.

(여담으로 말하자면 지금 보니 KEY_INDEX, VALUE_INDEX 라고 지은건 네이밍이 구리네요 ..^^..)

Comment on lines +10 to +11
private static final String QUERY_STRING_DELIMITER = "&";
private static final String QUERY_STRING_SEPARATOR = "=";
Copy link
Member

Choose a reason for hiding this comment

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

오호 하나 알게 되었네요 감사합니다 ㅎㅎ

@yeonkkk yeonkkk merged commit 11d8cf2 into woowacourse:jeomxon Sep 14, 2023
2 checks passed
@jeomxon jeomxon deleted the step2 branch September 14, 2023 05:27
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.

2 participants