Skip to content

[레베카] 3단계 - HTTP 웹 서버 리팩토링 미션 제출합니다.#179

Open
chws wants to merge 18 commits intowoowacourse:chwsfrom
chws:step3-rebase
Open

[레베카] 3단계 - HTTP 웹 서버 리팩토링 미션 제출합니다.#179
chws wants to merge 18 commits intowoowacourse:chwsfrom
chws:step3-rebase

Conversation

@chws
Copy link
Copy Markdown

@chws chws commented Oct 28, 2020

안녕하세요!
많은 지적 부탁드립니다:-)
감사합니다

chws and others added 18 commits October 28, 2020 16:10
- HttpSessionStorage.addSession에서 httpSession을 리턴하는 방식 수정
- HttpResponseHeaderParser에서 Set-Cookie에 Path 추가
- UserLogoutController 작성
- 추상 클래스 AuthController를 작성하여 세션을 가져오는 메소드 추가
- Set-Cookie 구현 방식 수정
Copy link
Copy Markdown

@jeonghoon1107 jeonghoon1107 left a comment

Choose a reason for hiding this comment

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

안녕하세요 레베카!
구현 잘 해주셨네요.
간단한 피드백을 남겼으니 확인해주세요.
중복되는 내용은 별도로 남기지 않았어요!

@Override
public HttpResponse get(HttpRequest httpRequest) {
try {
TemplateLoader loader = new ClassPathTemplateLoader();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

template 부분과 비즈니스로직을 분리해보면 어떨까요?

public abstract class AuthController extends Controller {
protected HttpSession retrieveHttpSession(HttpRequest httpRequest) {
if (httpRequest.hasCookie("SESSIONID")) {
HttpSession httpSession = HttpSessionStorage.getSession(httpRequest.getSessionId());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

getSession을 했을 때 존재하지 않으면 내부에서 만들어주면 어떨까요?

HttpSessionStorage를 controller까지 오픈할 필요는 없을 것 같아요.

boolean auth = userService.authenticateUser(httpRequest);
String header;
HttpSession httpSession;
Cookie cookie = new Cookie();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cookie 객체 생성을 내부로 감추면 어떨까요?

public class UserLogoutController extends AuthController {
@Override
public HttpResponse get(HttpRequest httpRequest) {
String header;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

선언과 대입을 분리한 이유가 있나요?

public class HttpSessionStorage {
private static Map<String, HttpSession> storage = new HashMap<>();

public static HttpSession addSession(HttpSession httpSession) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

내부에서만 사용한다면 접근제어자를 수정하면 어떨까요?


import static org.assertj.core.api.Assertions.assertThat;

class CookieTest {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

예외 케이스에 대한 테스트가 추가되면 좋을 것 같아요

}

public static String badRequest() {
return "HTTP/1.1 400 Bad Request \r\n" +
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

시스템 OS에 따라 개행이 달라질 수 있는데 System.lineSeparator()를 사용하면 어떨까요?

public boolean authenticateUser(HttpRequest httpRequest) {
String userId = httpRequest.getBodyValue("userId");
String password = httpRequest.getBodyValue("password");
User userById = DataBase.findUserById(userId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional을 반환해도 좋을 것 같네요

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.

3 participants