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단계] 오리(오현서) 미션 제출합니다 #345

Merged
merged 42 commits into from
Sep 6, 2023

Conversation

carsago
Copy link

@carsago carsago commented Sep 4, 2023

부탁드립니다 우석씨

Http11Processor에서 httpRequest를 생성

Handler로 넘김

Handler에서 requestHandler로 넘기고, httpResponse로 반환

HttpResponseParser가 response를 parse하여 byte 형태로 반환

Http11Processor가 잘 처리합니다.

**** 9월 4일, 17시 11분
-- 로그인 페이지에 들어갔을 때, 로그인 여부를 확인해야하는데, 로그인 요청시에 하도록 했네요 ㅠ

@carsago carsago self-assigned this Sep 4, 2023
@sonarcloud
Copy link

sonarcloud bot commented Sep 4, 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 19 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

@@ -9,13 +10,15 @@
public class InMemoryUserRepository {

private static final Map<String, User> database = new ConcurrentHashMap<>();
private static final AtomicLong id = new AtomicLong(2L);

Choose a reason for hiding this comment

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

오 이런 역할을 해주는 클래스가 있었군요! 배우고 갑니다!

return signUp(request);
}

throw new IllegalArgumentException();
Copy link

@Songusika Songusika Sep 5, 2023

Choose a reason for hiding this comment

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

해당 상황은 적절한 요청 핸들러가 없어서 발생하는 것이네요!
사용자가 옳바르지 않은 요청을 보내는 것이 정말 예외인 상황일까요?
어떻게 보면 이부분도 우리가 예측할 수 있는 상황인 것 같아요
예외 보다는 404를 내려주는 것이 어떨까요?
image

private static final Logger log = LoggerFactory.getLogger(Http11Processor.class);

public HttpResponse handle(HttpRequest request) throws IOException {
if (request.getUri().equals("/") && request.getMethod() == HttpMethod.GET) {

Choose a reason for hiding this comment

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

request 에서 직접 관련 필드를 꺼내오는 것보다.
request 객체한테 직접 물어볼 수 있을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

이 부분에 대해서 request 한테 너무 디테일한 책임을 주면 끝도 없이 메소드가 많아 질 것 같아서, 최소한으로하고 가독성만 개선해볼게요.

private HttpResponse getFile(HttpRequest request) throws IOException {
String fileUrl = "static" + request.getUri();
File file = new File(
RequestHandler.class

Choose a reason for hiding this comment

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

이 부분은 궁금한 것 인데요!
ClassLoader.getSystemClassLoader() 말고 클래스 리터럴을 사용하는 이유가 있을까요?

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 108 to 117
private HttpResponse signUp(HttpRequest request) {
Map<String, String> body = request.getBody();
InMemoryUserRepository.save(new User(
body.get("account"),
body.get("password"),
body.get("email")
));
return HttpResponse.found("/index.html");
}
}

Choose a reason for hiding this comment

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

사용자가 acc, pw 와 같은 변수로 요청을 보낼 수 도 있을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

이 부분은 null체크가 필요하다는 말씀이실까요?

Choose a reason for hiding this comment

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

맞습니다!


private static final RequestHandler requestHandler = new RequestHandler();

public static byte[] handle(HttpRequest request) {

Choose a reason for hiding this comment

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

HttpRequest 라는 객체를 파라미터로 받고 있어서 HttpResponse 라는 걸 예상하는데 바이트 배열을 return 하고 있네요.
파싱 부분은 Http11Processor 에서 해도 괜찮을 것 같은데 (request 에 대한 파싱도 해당 클래스에서 하기 때문입니다.)
핸들러에서 처리 후 바이트 배열을 반환하는 이유가 있나요?


private final Map<String, String> values = new ConcurrentHashMap<>();

public HttpRequest(InputStream inputStream) throws IOException {

Choose a reason for hiding this comment

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

HttpResponse 객체는 별도의 파서를 두셨는데 HttpRequest 객체도 별도의 파서를 두는 것이 어떨까요? 😀
생성자를 통해서 필요한 객체를 넘기면 실제 HttpRequest가 어떤 값들로 이루어져 있는지 더 쉽게 알 수 있을 것 같아요!

  • 테스트 코드도 더 짜기 쉬워 질 것 같습니다!


public class HttpResponse {

private Map<String, String> headers;

Choose a reason for hiding this comment

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

final 누락! 👀

HttpResponse response = requestHandler.handle(request);
return HttpResponseParser.parse(response);
} catch (IOException e) {
throw new RuntimeException(e);

Choose a reason for hiding this comment

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

runtimeException 대신 500 에러를 내려주는 것은 어떨까요?


private boolean isLogin(HttpRequest request) {
HttpCookie cookie = request.getCookie();
if (cookie == null) {
Copy link

@Songusika Songusika Sep 5, 2023

Choose a reason for hiding this comment

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

이 부분도 Optional 을 사용할 수 있지 않을까요?

Copy link

@Songusika Songusika left a comment

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 6, 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 11 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

@Songusika Songusika left a comment

Choose a reason for hiding this comment

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

1,2 단계 구현하시느라 고생많으셨습니다!!
전체적으로 코드가 깔끔해서 리뷰하기가 편했어요!
정말 궁금해서 드린 질문 1,2 개 있는데 편하실때 남겨주시면 감사하겠습니다!
다음 미션에서 봬요!

HttpResponse response = requestHandler.handle(request);
return HttpResponseParser.parse(response);
} catch (IOException e) {
HttpResponse response = HttpResponse.found("/500.html");

Choose a reason for hiding this comment

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

good 👍

return getFile(uri);
}

return getFile("/404.html");

Choose a reason for hiding this comment

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

good 👍

@@ -0,0 +1,9 @@
package nextstep.jwp;

public class Constant {

Choose a reason for hiding this comment

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

어떤 상수를 정의하는 건지 더 상세하면 좋을 것 같아요!

private Constant() {
}

public static final String CRLF = "\r\n";

Choose a reason for hiding this comment

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

System.lineSeparator() 를 활용할 수 도 있어요!


public static HttpResponse found(String location) {
Map<String, String> headers = new LinkedHashMap<>();
headers.put(HttpHeaders.CONTENT_LENGTH, "0");

Choose a reason for hiding this comment

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

body가 없을 때는 Content-Length 를 0으로 명시 혹은 해당 헤더를 넣지 않아도 되는데
오리는 어떤 이유로 0으로 직접 명시한지 기준이 궁금해요! (정말 궁금)

Copy link
Author

Choose a reason for hiding this comment

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

들어가야하는 줄 알았어요. 정말 몰랐음

@Songusika Songusika merged commit 54066a6 into woowacourse:carsago Sep 6, 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