-
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단계] 파워(송재백) 미션 제출합니다 #348
Conversation
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.
안녕하세요 파워
전체적인 코드 흐름이나 역할 분리가 잘 되어있는 것 같아요.
리뷰 한번만 확인해주시고 수정하고 싶으신거 수정하시고 다시 요청주시면 될 것 같습니다.
} | ||
} | ||
} | ||
package org.apache.coyote.http11;import java.io.IOException;import java.net.Socket;import java.net.URISyntaxException;import nextstep.jwp.exception.UncheckedServletException;import org.apache.coyote.Processor;import org.apache.coyote.http11.request.HttpRequest;import org.apache.coyote.http11.response.HttpResponse;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Http11Processor implements Runnable, Processor { private static final Logger log = LoggerFactory.getLogger(Http11Processor.class); private final Socket connection; public Http11Processor(final Socket connection) { this.connection = connection; } @Override public void run() { log.info("connect host: {}, port: {}", connection.getInetAddress(), connection.getPort()); process(connection); } @Override public void process(final Socket connection) { try (final var inputStream = connection.getInputStream(); final var outputStream = connection.getOutputStream()) { HttpRequest httpRequest = HttpRequest.of(inputStream); HttpResponse httpResponse = new HttpResponse(); HttpServletMapper httpServletMapper = new HttpServletMapper(); HttpServlet httpServlet = httpServletMapper.get(httpRequest.getPath()); httpServlet.service(httpRequest, httpResponse); outputStream.write(httpResponse.generateResponse()); outputStream.flush(); } catch (IOException | UncheckedServletException e) { log.error(e.getMessage(), e); } catch (URISyntaxException e) { throw new RuntimeException(e); } }} |
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.
개행이 해당 클래스만 CR로 되어있었네요
String[] pairs = cookies.split(COOKIE_DELIMITER); | ||
for (String pair : pairs) { | ||
String[] cookie = pair.split(KEY_VALUE_DELIMITER); | ||
httpCookies.put(cookie[KEY_INDEX].strip(), cookie[VALUE_INDEX].strip()); |
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.
cookie delimiter를 "; "로 하면 strip을 안해도 될 것 같아요
doGet(req, res); | ||
if(res.isNotRedirect()){ | ||
//FIXME: 임시로 요청을 구별하기 위한 코드 | ||
if(!req.getPath().contains(".")){ |
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.
url을 파일형식으로 바꾸는건 다른 객체의 역할로 바꿀 수 있을 것 같아요
public void doGet(final HttpRequest req, final HttpResponse resp) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public void doPost(final HttpRequest req, final HttpResponse resp) { | ||
throw new UnsupportedOperationException(); | ||
} |
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.
abstract method가 아닌 이유가 뭔가요 (진짜 모름)
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.
HttpServlet에 HttpMethod를 모두 abstract method만든다면
public enum HttpMethod {
GET,
HEAD,
POST,
PUT,
PATCH,
DELETE,
OPTIONS,
TRACE
}
Get 요청만 받는 ResourceController
경우 나머지 HttpMethod메서드를 모두 오버라이드후
throw new UnsupportedOperationException(); 작성해줘야해서
abstract method를 사용하지않았어요
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> requestHeaders = new LinkedHashMap<>(); | ||
|
||
String line; | ||
while (!"".equals(line = bufferedReader.readLine())) { |
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.
isBlank 를 쓰는 건 어떤가요
|
||
public HttpRequestHeaders add(String key, String value) { | ||
handlerMap.put(key.toLowerCase(), value); | ||
return new HttpRequestHeaders(handlerMap); |
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.
return this 대신 새로운 객체를 만드는 이유가 뭔가요? (진짜 모름)
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.
아마 방어적복사를 할려고했던것같아요,,,
HttpRequestHeaders에는 아직까지는 add가 필요가 없었네요,, 지웠습니다,, 😭
|
||
//FIXME: 쿠키를 여러개 설정할 수 있도록 수정 | ||
public void addCookie(final String key, final String value) { | ||
headers.add("Set-Cookie", key + KEY_VALUE_DELIMITER + 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.
Set-Cookie를 enum이나 상수화하는 것 어떤가요
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.
enum으로 표현하기에는 쿠키 key에는 다양한값이 들어갈수있어서 상수클래스를 만들었습니다!
"Content-Type: text/html;charset=utf-8 ", | ||
"Content-Length: 12 ", | ||
"", | ||
"Hello world!"); |
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.
그리고 테스트 추가로 더 있으면 좋을 것 같아요
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.
Hello world!가 홈화면이였군요,,,
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.
안녕하세요 power, jude입니다.
1,2단계 요구사항은 충분히 만족한 것 같습니다.
아니 어쩌면 3단계까지도..?
코멘트 한번씩만 확인해주시고 다음 단계에서 만나시죠
잘 배우고 갑니다
if (findAccount.isPresent()) { | ||
User user = findAccount.get(); | ||
if (user.checkPassword(requestParam.get("password"))) { |
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.
Optional의 ifPresent같은 메서드를 활용한다면 옵셔널을 더 의미있게, 그리고 가독성 좋은 코드를 만들 수 있을 것 같습니다.
private static final String PREFIX = "static"; | ||
private static final String SUFFIX = ".html"; |
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.
중복이 발생하는 것 같아요 다른 좋은 방법은 없을까요? 스프링에선 ViewResolver가 이런 역할을 하고 있는 걸로 알고 있습니다
public void doGet(final HttpRequest req, final HttpResponse resp) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public void doPost(final HttpRequest req, final HttpResponse resp) { | ||
throw new UnsupportedOperationException(); | ||
} |
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.
취약한 기반 클래스 문제에 대해 들어보셨나요?
사실 이건 원래 구현도 이런 구조일 것 같아서 넘어가셔도 될 것 같습니다
안녕하세요 주드! 잘부탁드려요
step1에서 step2까지 작업해버렸어요,,
전체적인 흐름은 아래와 같습니다.