-
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
[톰캣 구현하기 3, 4단계] 루쿠(백경환) 미션 제출합니다. #488
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.
안녕하세요 루쿠!!
미션 3,4단계 수고하셨습니다~~
저번에 말씀해주신대로 리팩토링을 야무지게 해주셨네요 😄
코드 읽으면서 궁금한 부분들 질문 남겨놨습니다ㅎㅎㅎ
전체적으로 상수 추출, 공백 정리, 테스트 작성만 좀 더 해주면 좋을 것 같아요!
다음 요청 주시면 바로 머지하겠습니다!
String requestFileName = requestPath.substring(requestPath.lastIndexOf('/') + 1); | ||
String requestBody = httpRequest.getBody(); | ||
Map<String, String> headers = httpRequest.getHeaders(); | ||
RequestMapping requestMapping = new RequestMapping(); |
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.
모든 요청마다 RequestMapping 객체를 새로 생성해주는 이유가 있나용??
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 Controller getController(HttpRequest request) { | ||
if (request.getPath().equals("/login")) { | ||
return new LoginController(); | ||
} | ||
|
||
if (request.getPath().equals("/register")) { | ||
return new RegisterController(); | ||
} | ||
|
||
if (request.getPath().equals("/")) { | ||
return new RootController(); | ||
} | ||
|
||
return new ResourceController(); | ||
} |
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.
마찬가지로 모든 요청마다 LoginController, RegisterController 등을 새로 만들어 주는 이유가 있나요?!
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.
예리하시군요,.. map에다가 담아 사용하도록 수정하였습니다
@@ -4,13 +4,15 @@ | |||
import java.util.Map; | |||
|
|||
public class HttpResponse { | |||
private final StringBuilder status = new StringBuilder(); | |||
private HttpStatus status; | |||
private final Map<String, String> headers = new HashMap<>(); | |||
private final StringBuilder body = new StringBuilder(); | |||
|
|||
public String createResponse() { |
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.
뭔가 createResponse
라는 이름을 보면 HttpResponse
를 만드는 정적팩토리메소드인 느낌이 드는데,
실제로 반환하는 값은 Http 응답 포맷에 맞춘 String
이네용!!
메소드명을 살짝 수정해보는 것은 어떨까요?!
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 final Map<String, String> headers = new HashMap<>(); | ||
private final StringBuilder body = new StringBuilder(); | ||
|
||
public String createResponse() { | ||
StringBuilder responseBuilder = new StringBuilder(); | ||
responseBuilder.append("HTTP/1.1 ").append(status).append("\r\n"); | ||
responseBuilder.append("HTTP/1.1 ") |
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.
builder 👍
import org.apache.catalina.Manager; | ||
|
||
public class SessionManager implements Manager { | ||
|
||
private static final Map<String, Session> SESSIONS = new HashMap<>(); | ||
private static final Map<String, Session> SESSIONS = new ConcurrentHashMap<>(); |
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.
HashMap
대신 ConcurrentHashMap
을 사용한 이유가 뭔가요??
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.
그리고 SESSIONS는 상수일까요?! 루쿠의 의견이 궁금해요~~
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.
해시맵은 멀티 쓰레드시로 사용시 동기화가 이루어지지 않으므로 내부적으로 동기화 처리를하는ConcurrentHashMap
을 사용하였습니다~
SESSIONS은 map의 값이 고정되지 않고 세션이 추가되거나 제거될수 있으니 상수는 아닌거같아요! 그래서 변수명도 소문자로 수정하였습니다
|
||
|
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.
공백~~
|
||
assertThat(controller).isInstanceOf(RegisterController.class); | ||
} | ||
|
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.
공백~~~
@Test | ||
@DisplayName("올바른 매핑인지 확인1") | ||
void getController1() { | ||
RequestMapping requestMapping = new RequestMapping(); | ||
HttpRequest httpRequest = new HttpRequest(null, "/login", null, null); | ||
Controller controller = requestMapping.getController(httpRequest); | ||
|
||
assertThat(controller).isInstanceOf(LoginController.class); | ||
} | ||
|
||
@Test | ||
@DisplayName("올바른 매핑인지 확인2") | ||
void getController2() { | ||
RequestMapping requestMapping = new RequestMapping(); | ||
HttpRequest httpRequest = new HttpRequest(null, "/register", null, null); | ||
Controller controller = requestMapping.getController(httpRequest); | ||
|
||
assertThat(controller).isInstanceOf(RegisterController.class); | ||
} |
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.
ParameterizedTest
를 활용해 보는 것은 어떨까요??
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.
좋아요~
User user = new User(queryParms.get("account"), queryParms.get("password"), | ||
queryParms.get("email")); |
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.
queryParams에 account
, password
, email
중 하나라도 없으면 User에 잘못된 값이 들어갈 것 같은데,
살짝의 방어로직을 추가해보는 것은 어떨까용??
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.
추가하였습니다!
if (fileName.endsWith(".html")) { | ||
response.setContentType("text/html"); | ||
response.setBody(Utils.readFile("static", fileName)); | ||
return; | ||
} | ||
|
||
if (fileName.equals("styles.css")) { | ||
response.setContentType("text/css"); | ||
response.setBody(Utils.readFile("static/css", fileName)); | ||
return; | ||
} | ||
|
||
if (fileName.endsWith(".js") && !fileName.equals("scripts.js")) { | ||
response.setContentType("text/javascript"); | ||
response.setBody(Utils.readFile("static/assets", fileName)); | ||
return; | ||
} | ||
|
||
if (fileName.equals("scripts.js")) { | ||
response.setContentType("text/javascript"); | ||
response.setBody(Utils.readFile("static/js", fileName)); | ||
return; | ||
} | ||
|
||
if (fileName.equals("favicon.ico")) { | ||
response.setContentType("text/javascript"); | ||
response.setBody("Hello world!"); | ||
return; | ||
} |
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.
지금 구조에서는
새로운 정적파일이 추가될 때마다 if 분기문이 계속해서 추가되어야 할 것 같은데
어떻게 생각하시나용??
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.
맞습니다 오잉이 말씀해주신것처럼 정적파일이 추가될때마다 If문이 추가될거같아요..
이부분에 대해서는 좀더 근본적인 방법이 잘 떠오르지 않아서 좀더 고민하고 생각해봐야할거같습니다 😭
안녕하세요 오잉~ |
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.
안녕하세요 루쿠!
3,4단계 너무너무 수고 많으셨어요~~
톰캣 미션은 여기서 마무리 하도록 하겠습니다!
다음 미션도 화이팅팅😋
안녕하세요 오잉
브랜치작업을 잘못 나누어서 커밋이 1,2단계 까지 같이 들어가버렸네요
따로 3,4단계에서 진행했던 커밋으로만 따로 지정했습니다!
커밋