[Tomcat 구현하기 3단계] 리건(이한길) 미션 제출합니다.#625
Conversation
lilychoibb
left a comment
There was a problem hiding this comment.
안녕하세요 리건 🤗!
리팩토링 잘 해주셨네요 :) 고생 많으셨습니다
몇 가지 코멘트 남겼는데, 확인 부탁드려요!
레벨 4가 되면서 다들 시간 관리에 대해서 고민이 많아진 것 같아요.
저도 미션과 프로젝트 병행을 아주 벅차게... 하고 있답니다 😇
그래도 같이 파이팅 해보아요 💪🏻💪🏻💪🏻
| public RequestMapping() { | ||
| requestMap.put(Request.ofGet("/login"), new LoginController()); | ||
| requestMap.put(Request.ofPost("/login"), new LoginController()); | ||
| requestMap.put(Request.ofGet("/register"), new RegisterController()); | ||
| requestMap.put(Request.ofPost("/register"), new RegisterController()); | ||
| } |
There was a problem hiding this comment.
Get 과 Post 요청을 분리해서 put 하는 이유가 궁금합니다!
get 을 하면 어차피 같은 Controller 를 반환해서 service 하는 것 같아서요
There was a problem hiding this comment.
각 요청에 따라 컨트롤러를 분리해놨다가 리팩토링하면서 놓쳤네요.
고쳐보겠습니다!
| import org.apache.coyote.http11.HttpMethod; | ||
| import org.apache.coyote.http11.request.HttpRequest; | ||
|
|
||
| public class Request { |
There was a problem hiding this comment.
RequestLine 객체와 같은 역할을 하는 것 같은데 추가하신 이유가 궁금해요 🙂
그리고 http 요청을 처리하는 클래스가 controller 패키지에 있는 느낌이 들었어요!
There was a problem hiding this comment.
지금 확인해보니 역할이 동일하네요.. 하나로 통일하겠습니다.
http11 패키지에 의존성을 갖네요. 이것도 고쳐보겠습니다!
| public void addCookies(final HttpCookie cookie) { | ||
| headers.addFirst(HttpHeader.setCookie(cookie)); |
There was a problem hiding this comment.
21 에서 addFirst 가 나왔군요 👍 덕분에 알아가요!
| public static HttpCookie from(final String cookies) { | ||
| if ("".equals(cookies)) { | ||
| return new HttpCookie(); | ||
| } | ||
| return new HttpCookie(cookies.strip()); |
| EMPTY_LINE, | ||
| responseBody | ||
| ).getBytes(); | ||
| private String statusLine = ""; |
There was a problem hiding this comment.
statusLine 의 Http 버전과 statusCode 는 분리를 안해도 될까요?
추후 버전이 다른 http 를 쓸 경우에 재사용을 할 수 있을 것 같아서요!
리건의 의견이 궁금합니다🙂
There was a problem hiding this comment.
재사용성을 두고 보니 릴리의 의견에 동의합니다. 이 역시 리팩토링 해보겠습니다.
| public HttpMethod from(final String method) { | ||
| return HttpMethod.valueOf(method); | ||
| } |
There was a problem hiding this comment.
이 메서드는 사용되고 있지 않은 것 같은데 미리 만들어두신 이유가 있을까요?
static 도 붙어있지가 않아 조금 어색하네요 🙂
| final String requestString = String.join("\r\n", | ||
| "GET /login HTTP/1.1 ", | ||
| "Host: localhost:8080 ", | ||
| "Connection: keep-alive ", |
There was a problem hiding this comment.
해당 헤더는 테스트 하는데 꼭 필요한 헤더인가요?
저도 잘 몰라서 여쭤봐요!
There was a problem hiding this comment.
앗! 이것도 놓쳤네요.. 중복 제거하겠습니다..
| import java.io.IOException; | ||
| import org.apache.coyote.http11.request.HttpRequest; | ||
|
|
||
| public class HttpRequestFixture { |
There was a problem hiding this comment.
해당 fixture 덕분에 테스트 읽기가 수월했어요 👍
lilychoibb
left a comment
There was a problem hiding this comment.
안녕하세요 리건 🙂
리뷰 잘 반영해주셨네요!
몇 가지 코멘트 더 남겼는데 꼭 확인해주시고 4단계에 함께 반영해주세요!!
4단계도 파이팅입니다 👍
| @@ -0,0 +1,28 @@ | |||
| package com.techcourse.controller; | |||
There was a problem hiding this comment.
해당 패키지에 있는 Login, Register Controller 와 나머지 Controller 의 역할이 조금 다른 것 같은데 패키지를 분리하시는 건 어떻게 생각하시나요? 🙂
There was a problem hiding this comment.
이번 미션하면서 패키지 구분이 정말 어려운 것 같습니다.
이름은 같은 Controller이지만 확연하게 하는 역할이 달라 패키지를 어떻게 구성해야 할지 정말 고민됩니다..
조금 더 고민해보겠습니다!
| if ("/".equals(url)) { | ||
| buildIndexUrlResponse(response); | ||
| } | ||
| if (url.endsWith(HTML_SUFFIX)) { | ||
| buildResourceResponse(response, FileType.HTML, url); | ||
| } | ||
| if (url.endsWith(CSS_SUFFIX)) { | ||
| buildResourceResponse(response, FileType.CSS, url); | ||
| } | ||
| if (url.endsWith(JS_SUFFIX)) { | ||
| buildResourceResponse(response, FileType.JAVASCRIPT, url); | ||
| } |
There was a problem hiding this comment.
MIME types 를 조금 더 단순하게 가져올 순 없을까요? 🤔
There was a problem hiding this comment.
조금 더 고민해보겠습니다..
당장 떠오르는 건 FileType 클래스가 직접 본인의 미디어 타입을 결정하도록 책임을 넘길 수 있겠네요..
| private boolean isLogin(final HttpRequest request, final HttpResponse response) { | ||
| final var cookies = request.getCookies(); | ||
| if (cookies.containsSession() && hasSession(cookies)) { | ||
| final var session = SessionManager.findSession(cookies.getSessionCookie()); |
There was a problem hiding this comment.
위의 createSession 메서드에서는 Session session 인데 여기선 var 이네요
통일해주는 건 어떨까요?
전체적으로도 통일이 필요할 것 같아요!
There was a problem hiding this comment.
var 키워드를 사용했을 때 코드 가독성이 더 떨어지는 상황이 발생하네요.
전반적으로 코드 검토하고 한 방향으로 통일하겠습니다!
| @@ -68,14 +75,17 @@ public Map<String, String> getHeaders() { | |||
|
|
|||
| public HttpCookie getCookies() { | |||
| final String cookieString = headers.getOrDefault("Cookie", ""); | |||
There was a problem hiding this comment.
여기랑 from 메서드에 헤더 문자열이 있는데, 이것도 HttpHeaderName 을 사용하는 건 어떠신가요?
| this.path = path; | ||
| } | ||
|
|
||
| public static RequestLine of(final String requestLine) { |
There was a problem hiding this comment.
of 라고 네이밍 해주신 이유가 궁금해요!
다른 곳은 from 으로 되어있는 것 같아서요 🙂
There was a problem hiding this comment.
단일 파라미터에 대한 정적 팩토리 메소드는 from으로 통일했는데 여기서 놓쳤네요!
꼼꼼한 리뷰 감사합니다!
| final String requestString = String.join("\r\n", | ||
| "POST /login HTTP/1.1 ", | ||
| "Host: localhost:8080 ", | ||
| "Connection: keep-alive ", | ||
| "Content-Length: 30", | ||
| "Content-Type: application/x-www-form-urlencoded ", | ||
| "Accept: */*", | ||
| "", | ||
| "account=gugu&password=password "); |
There was a problem hiding this comment.
requestString 에서 테스트 하는 데 필요한 header 만 추려보면 어떨까요?
HttpRequestFixture 에 있는 requestString 모두를 점검해보면 좋을 것 같아요!
안녕하세요, 릴리! 👋
일정 관리가 여간 어려운게 아니네요.. 😢
릴리는 미션과 프로젝트 잘 병행하고 있나요?
최대한 열심히 리팩토링 해봤습니다!
리뷰 잘 부탁드려요!