-
Notifications
You must be signed in to change notification settings - Fork 309
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단계] 로이스(원태연) 미션 제출합니다. #307
Conversation
- 다중 assertions 방식에서 chaining 방식으로 변경 - logger 사용 - 람다 내부에서 메서드 호출이 한번만 발생하도록 변경
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 로이스~ 마코입니다!
빨리 리뷰해드리고 싶었는데 미션도 진행하고 리뷰가 생각보다 쉽지 않네요😅
벌써부터 MVC를 멋지게 구현하신것을 보고 많이 배웠습니다👍👍
자잘하게 고려하실만한 부분들이나 궁금한 부분들이 있어서 코멘트 남겼으니 확인해주세요!
*/ | ||
@Test | ||
void resource_디렉터리에_있는_파일의_경로를_찾는다() { | ||
final String fileName = "nextstep.txt"; | ||
|
||
// todo | ||
final String actual = ""; | ||
final URL resource = getClass().getClassLoader().getResource(fileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤 과정으로 resource를 찾아내나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
동적으로 클래스를 포함한 자바 파일들을 메모리에 로딩하는 ClassLoader
에서 해당하는 자원을 찾아 URI를 반환합니다. (이때, 최상위 BootLoader까지 위임하여 찾으므로 절대경로를 사용해야 하는 것 같습니다!
그리고 JVM에 로딩한 ClassLoader를 얻기 위해 FileTest.getClass().getClassLoader()
를 사용한 것 같습니다..!
@@ -96,27 +99,26 @@ class OutputStream_학습_테스트 { | |||
* try-with-resources를 사용한다. | |||
* java 9 이상에서는 변수를 try-with-resources로 처리할 수 있다. | |||
*/ | |||
outputStream.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try-with-resources를 사용하라는 요구사항을 만족시켜 주시면 좋을 것 같네요👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!
|
||
private String removeHtmlExtension(final String requestURI) { | ||
if (requestURI.endsWith(HTML_EXTENSION)) { | ||
return requestURI.substring(0, requestURI.length() - HTML_EXTENSION.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 부분에서는 requestURI.lastIndexOf(HTML_EXTENSION)
이렇게 사용하셨던데 저는 lastIndexOf가 더 깔끔한 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다! 일관성이 많이 흐트려저있네요. 수정했습니다!
final Map<String, String> cookieKeyValues = Arrays.stream(cookieHeader.split(COOKIE_SEPARATOR)) | ||
.map(param -> param.split(COOKIE_DELIMITER)) | ||
.collect(Collectors.toMap(e -> e[0], e -> e[1])); | ||
return new HttpCookie(cookieKeyValues); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메시지 형식에 맞게 쿠키를 파싱하는 작업은 HttpCookie
보다는 HttpRequestMessageReader
의 책임에 더 가깝지 않을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
쿠키 형식에 맞게 요청을 읽는 역할을 Reader에서 수행 한 뒤, HttpCookie를 생성하는게 자연스러워 보이네요!
좋은 의견 감사합니다.
tomcat/src/main/java/org/apache/coyote/http11/mvc/AbstractController.java
Show resolved
Hide resolved
tomcat/src/main/java/org/apache/coyote/http11/request/parser/HttpRequestMessageReader.java
Show resolved
Hide resolved
import java.util.Map; | ||
import org.apache.coyote.http11.common.HttpMethod; | ||
|
||
public class HttpRequestStartLine { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RFC2616에 따르면
request의 첫 라인을 Request-Line,
response의 첫 라인을 Status-Line,
둘 다를 합쳐서 Start-Line이라고 부릅니다.
현재 이 클래스는 Request에서만 사용되고 있는 것 같은데요, Request에서만 사용되는 첫 라인이라면 HttpRequestLine
과 같은 이름이 더 표준 스펙에 가까운 네이밍 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
참고 자료 감사합니다!
제가 혼동해서 사용하고 있었네요.
마코 말씀대로 HttpRequestLine
라는 네이밍이 제 의도에도 맞고 표준 네이밍이군요.
반영하였습니다!
private static String parseResponseHeaders(final HttpHeaders httpHeaders) { | ||
return httpHeaders.getHeaders().entrySet().stream() | ||
.map(entry -> String.join(": ", entry.getKey(), entry.getValue() + " ")) | ||
.collect(Collectors.joining("\r\n")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오류 확인하고 수정했습니다!
tomcat/src/test/java/org/apache/coyote/http11/common/HttpCookieTest.java
Outdated
Show resolved
Hide resolved
tomcat/src/main/java/org/apache/coyote/http11/request/parser/HttpRequestMessageReader.java
Outdated
Show resolved
Hide resolved
HttpRequestStartLine -> HttpRequestLine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마코, 꼼꼼함이 조금 부족한 코드였는데 잘 읽어주시고 좋은 리뷰 남겨주셔서 감사합니다!
남겨 주신 리뷰는 간단한 코멘트와 함께 반영 완료하였습니다!
그리고 말씀해주신 resource 찾는 방법에 대해 덕분에 학습할 수 있었습니다. 감사해요!
return new HttpHeaders(headers); | ||
} | ||
|
||
public void setHeader(final String header, final String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addHeader가 더 직관적이고 좋네요! 감사합니다
@@ -96,27 +99,26 @@ class OutputStream_학습_테스트 { | |||
* try-with-resources를 사용한다. | |||
* java 9 이상에서는 변수를 try-with-resources로 처리할 수 있다. | |||
*/ | |||
outputStream.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!
|
||
public static HttpMethod from(final String method) { | ||
return Arrays.stream(HttpMethod.values()) | ||
.filter(httpMethod -> httpMethod.name().equals(method.toUpperCase())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일관성 있게 수정했습니다!
|
||
private String removeHtmlExtension(final String requestURI) { | ||
if (requestURI.endsWith(HTML_EXTENSION)) { | ||
return requestURI.substring(0, requestURI.length() - HTML_EXTENSION.length()); |
There was a problem hiding this comment.
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.common.HttpMethod; | ||
|
||
public class HttpRequestStartLine { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
참고 자료 감사합니다!
제가 혼동해서 사용하고 있었네요.
마코 말씀대로 HttpRequestLine
라는 네이밍이 제 의도에도 맞고 표준 네이밍이군요.
반영하였습니다!
tomcat/src/main/java/org/apache/coyote/http11/request/parser/HttpRequestMessageReader.java
Show resolved
Hide resolved
private static String parseResponseHeaders(final HttpHeaders httpHeaders) { | ||
return httpHeaders.getHeaders().entrySet().stream() | ||
.map(entry -> String.join(": ", entry.getKey(), entry.getValue() + " ")) | ||
.collect(Collectors.joining("\r\n")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오류 확인하고 수정했습니다!
tomcat/src/main/java/org/apache/coyote/http11/request/parser/HttpRequestMessageReader.java
Outdated
Show resolved
Hide resolved
final Map<String, String> cookieKeyValues = Arrays.stream(cookieHeader.split(COOKIE_SEPARATOR)) | ||
.map(param -> param.split(COOKIE_DELIMITER)) | ||
.collect(Collectors.toMap(e -> e[0], e -> e[1])); | ||
return new HttpCookie(cookieKeyValues); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
쿠키 형식에 맞게 요청을 읽는 역할을 Reader에서 수행 한 뒤, HttpCookie를 생성하는게 자연스러워 보이네요!
좋은 의견 감사합니다.
*/ | ||
@Test | ||
void resource_디렉터리에_있는_파일의_경로를_찾는다() { | ||
final String fileName = "nextstep.txt"; | ||
|
||
// todo | ||
final String actual = ""; | ||
final URL resource = getClass().getClassLoader().getResource(fileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
동적으로 클래스를 포함한 자바 파일들을 메모리에 로딩하는 ClassLoader
에서 해당하는 자원을 찾아 URI를 반환합니다. (이때, 최상위 BootLoader까지 위임하여 찾으므로 절대경로를 사용해야 하는 것 같습니다!
그리고 JVM에 로딩한 ClassLoader를 얻기 위해 FileTest.getClass().getClassLoader()
를 사용한 것 같습니다..!
Kudos, SonarCloud Quality Gate passed! 0 Bugs 0.0% Coverage 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 잘 반영해주셨군요 👍
더 많은 도움을 드리고 싶지만 이미 구조도 멋지고 잘 만들어져있어서 제가 크게 도움을 드릴건 없어보이네요ㅎㅎㅎ
더 리팩토링 하시고 싶으신 것도 있으신 것 같아서 머지해드릴테니 리팩토링 + 다음 단계 함께 진행해주시면 될 것 같습니다! 고생하셨습니다~
안녕하세요, 마코! 리뷰요청 드립니다.
MVC를 학습하면서 만들다 보니 레벨3의 구조를 약간 침범하고 있었다는걸 추후에 알게되었습니다.(
HttpRequest
,HttpResponse
,Controller
, ...)여전히 리팩토링 할 부분이 많아 유지한채로 구현한 뒤, 더 개선해나갈 예정입니다.
이점 참고하여서 리뷰 해주시면 감사하겠습니다!
전체적인 흐름에 대한 플로우차트입니다! (
악필입니다)