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단계] 로이스(원태연) 미션 제출합니다. #307

Merged
merged 50 commits into from
Sep 5, 2023

Conversation

TaeyeonRoyce
Copy link
Member

@TaeyeonRoyce TaeyeonRoyce commented Sep 3, 2023

안녕하세요, 마코! 리뷰요청 드립니다.

MVC를 학습하면서 만들다 보니 레벨3의 구조를 약간 침범하고 있었다는걸 추후에 알게되었습니다.(HttpRequest, HttpResponse, Controller, ...)
여전히 리팩토링 할 부분이 많아 유지한채로 구현한 뒤, 더 개선해나갈 예정입니다.
이점 참고하여서 리뷰 해주시면 감사하겠습니다!

전체적인 흐름에 대한 플로우차트입니다! (악필입니다)
IMG_66E6F41735CF-1

- 다중 assertions 방식에서 chaining 방식으로 변경
- logger 사용
- 람다 내부에서 메서드 호출이 한번만 발생하도록 변경
@TaeyeonRoyce TaeyeonRoyce self-assigned this Sep 3, 2023
Copy link

@aak2075 aak2075 left a 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);
Copy link

Choose a reason for hiding this comment

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

어떤 과정으로 resource를 찾아내나요?

Copy link
Member Author

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();
Copy link

Choose a reason for hiding this comment

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

try-with-resources를 사용하라는 요구사항을 만족시켜 주시면 좋을 것 같네요👀

Copy link
Member Author

Choose a reason for hiding this comment

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

넵!

README.md Show resolved Hide resolved

private String removeHtmlExtension(final String requestURI) {
if (requestURI.endsWith(HTML_EXTENSION)) {
return requestURI.substring(0, requestURI.length() - HTML_EXTENSION.length());
Copy link

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가 더 깔끔한 것 같습니다

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 24 to 28
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);
}
Copy link

Choose a reason for hiding this comment

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

메시지 형식에 맞게 쿠키를 파싱하는 작업은 HttpCookie보다는 HttpRequestMessageReader의 책임에 더 가깝지 않을까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

쿠키 형식에 맞게 요청을 읽는 역할을 Reader에서 수행 한 뒤, HttpCookie를 생성하는게 자연스러워 보이네요!
좋은 의견 감사합니다.

import java.util.Map;
import org.apache.coyote.http11.common.HttpMethod;

public class HttpRequestStartLine {
Copy link

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과 같은 이름이 더 표준 스펙에 가까운 네이밍 같습니다!

Copy link
Member Author

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"));
Copy link

Choose a reason for hiding this comment

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

문제가 되지는 않지만 login에 성공해서 302 Found로 redirect하는 경우에 어디선가 Content-Length가 잘못 담겨 반환되는 경우가 있네요.
image

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
Member Author

@TaeyeonRoyce TaeyeonRoyce left a 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) {
Copy link
Member Author

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();
Copy link
Member Author

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()))
Copy link
Member Author

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());
Copy link
Member 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.common.HttpMethod;

public class HttpRequestStartLine {
Copy link
Member Author

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"));
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 24 to 28
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);
}
Copy link
Member Author

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);
Copy link
Member Author

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()를 사용한 것 같습니다..!

@sonarcloud
Copy link

sonarcloud bot commented Sep 5, 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 2 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

@aak2075 aak2075 left a comment

Choose a reason for hiding this comment

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

리뷰 잘 반영해주셨군요 👍

더 많은 도움을 드리고 싶지만 이미 구조도 멋지고 잘 만들어져있어서 제가 크게 도움을 드릴건 없어보이네요ㅎㅎㅎ

더 리팩토링 하시고 싶으신 것도 있으신 것 같아서 머지해드릴테니 리팩토링 + 다음 단계 함께 진행해주시면 될 것 같습니다! 고생하셨습니다~

@aak2075 aak2075 merged commit 6f593a7 into woowacourse:taeyeonroyce Sep 5, 2023
2 checks passed
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