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단계 - HTTP 웹 서버 구현 미션 제출합니다. #105

Merged
merged 18 commits into from
Sep 12, 2020

Conversation

jnsorn
Copy link

@jnsorn jnsorn commented Sep 12, 2020

안녕하세요, 후니! 또링입니다🙂
레벨4에서 처음 뵙게 되었네요ㅎㅎ
코드를 작성하면서 1단계의 요구사항인 기능 구현과 2단계의 요구사항인 리팩토링 사이에서 많은 고민이 됐던 것 같습니다.
어디까지 객체 분리를 해야하고, 어디서부터 2단계 리팩토링에서 적용해야할지 감이 잘 잡히지 않아 코드에 일관성이 떨어지는 부분이 있네요😓
많이 지적해주시면 열심히 고민하고 고쳐보겠습니다 😊

Copy link

@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.

안녕하세요 또링!
요구사항 잘 구현해주셨네요!
피드백을 남겼으니 리팩토링 미션에서 반영해주세요 :)

}

public void process(HttpRequest httpRequest) {
if (httpRequest.isStaticFile()) {
Copy link

@jeonghoon1107 jeonghoon1107 Sep 12, 2020

Choose a reason for hiding this comment

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

api가 추가되어도 해당 부분만 작업이 되도록 구조화가 되면 좋을 것 같아요.
예를 들면 path를 매핑하는 클래스를 만들고 doGet(request), doPost(response) 등을 갖는 인터페이스를 구현하여 관리해보면 어떨까요?(path를 찾아서 비즈니스로직을 실행하는 것은 response객체 밖에서 이루어지도록)

private void processApi(HttpRequest httpRequest) {
if (httpRequest.isPost()) {
Map<String, String> body = httpRequest.getRequestBody().getFormData();
User user = new User(body.get("userId"), body.get("password"), body.get("name"),

Choose a reason for hiding this comment

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

response가 하는 역할이 너무 많네요 😭

private static final int METHOD_INDEX = 0;
private static final int PATH_INDEX = 1;

private final Map<String, String> header;

Choose a reason for hiding this comment

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

일급 컬렉션으로 관리해보면 어떨까요?

private static final int PARAMETER_INDEX = 1;

private String uri;
private Map<String, String> parameters;

Choose a reason for hiding this comment

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

일급컬렉션으로!

User user = new User(body.get("userId"), body.get("password"), body.get("name"),
body.get("email"));
DataBase.addUser(user);
String response = response302Header("http://localhost:8080" + INDEX_HTML);

Choose a reason for hiding this comment

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

/index.html 만 주어도 될 것 같아요.

} else {
processApi(httpRequest);
}
}

Choose a reason for hiding this comment

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

404, 405 등에 대한 처리가 추가되면 어떨까요?

public class RequestUri {
public static final int URI_INDEX = 0;
public static final String PARAMETER_DELIMITER = "?";
static final String INDEX_HTML = "/index.html";

Choose a reason for hiding this comment

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

해당 클래스에 정의되어야 하나요?

}

public static Map<String, String> parsingData(String s) {
return Arrays.stream(s.split("&"))

Choose a reason for hiding this comment

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

중복되는 key가 들어오면 어떻게 될까요?

@jeonghoon1107 jeonghoon1107 merged commit fd1aed0 into woowacourse:jnsorn Sep 12, 2020
young891221 pushed a commit that referenced this pull request Nov 26, 2020
* [또링] 1단계 - HTTP 웹 서버 구현 미션 제출합니다. (#105)

* docs : 요구사항1의 구현 기능 목록 작성

* feat : 모든 Request Header 출력하기

* feat : Request에서 path 분리하기

* feat : path에 해당하는 파일 읽어 응답하기

* docs : 요구사항2의 구현 기능 목록 작성

* feat : Request Parameter 추출 및 User 객체 생성

* docs : 요구사항3의 구현 기능 목록 작성

* feat : form.html 파일의 form 태그 method를 get에서 post로 수정

* refactor : HttpRequest를 RequestHeader와 RequestBody로 분리

* refactor : HttpRequestParser 유틸 클래스 생성

* docs : 요구사항4의 구현 기능 목록 작성

* feat : 요청에 따라 다른 HttpResponse를 내려준다.

* docs : 요구사항5의 구현 기능 목록 작성

* refactor : RequestHeader 값의 자료형을 List에서 Map으로 변경

* refactor : HeaderProperty 생성

* feat : 응답에 따라 Content-Type을 변경하여 Stylesheet 파일을 지원하도록 구현

* feat : status code를 302로 변경한 후, Location 값에 리다이렉션 할 페이지를 넣어 응답

* refactor : 변수 정리 및 파일 끝 개행 추가

* docs: 3단계 요구사항1 구현 기능목록 작성

* feat: 로그인 기능 구현

* feat: default root 설정

* docs: 요구사항 2번째 기능 목록 작성

* test: handlebar 사용을 위한 학습테스트 작성

* feat: 로그인하지 않은 상태면 로그인 페이지로 이동

* feat: 유저 목록 출력하기

* feat: 로그인 성공 여부에 따라 페이지 redirect

* refactor: http package 구조 변경

* test: /user GET method에 대한 테스트 작성

* [또링] 2단계 - HTTP 웹 서버 리팩터링 미션 제출합니다. (#202)

* docs: README.md에 요구사항 1 추가

* feat: Request Handler에서 Header 추출 기능 구현

* feat: request의 path로 파일을 읽어서 응답하는 기능 추가

* feat: Http Request 생성

	- Http Method를 위한 클래스 생성
	- Http Status를 위한 클래스 생성
	- Http Header를 위한 클래스 생성

* feat: 요구사항1 완료

* docs: 두번째 요구사항 작성

* refactoring: http spec 정의

* refactoring: http request spec 추가 및 테스트 추가

* refactor: http request spec 변경

* feat: 요구사항2 완료

* docs: 요구사항3을 위한 README.md 작성

* feat: 회원 가입 기능이 post 요청에서 정상적으로 동작하도록 구현

* docs: 요구사항4 작성

* feat: 회원가입 완료 후 index.html로 이동하도록 변경

* docs: 요구사항 5 README.md에 작성

* feat: 요청 uri이 static resource인지를 확인하는 기능 생성

* feat: stylesheet 등 다양한 형식의 파일을 지원하도록 변경

* feat: Http Response 분리

* test: SimpleHttRequest에 대한 Test 작성

* test: HttpResponse에 대한 Test 작성

* refactor: HttpServlet 및 UserController 생성

* feat: DispatcherServlet 생성

* feat: ThreadPool 사용

* docs: 구현 내용 정리

* refactor: 사용하지 않는 파일 삭제

* [제이] 1단계 - HTTP 웹 서버 리팩터링 미션 제출합니다. (#198)

* docs: README.md에 요구사항 1 추가

* feat: Request Handler에서 Header 추출 기능 구현

* feat: request의 path로 파일을 읽어서 응답하는 기능 추가

* feat: Http Request 생성

	- Http Method를 위한 클래스 생성
	- Http Status를 위한 클래스 생성
	- Http Header를 위한 클래스 생성

* feat: 요구사항1 완료

* docs: 두번째 요구사항 작성

* refactoring: http spec 정의

* refactoring: http request spec 추가 및 테스트 추가

* refactor: http request spec 변경

* feat: 요구사항2 완료

* docs: 요구사항3을 위한 README.md 작성

* feat: 회원 가입 기능이 post 요청에서 정상적으로 동작하도록 구현

* docs: 요구사항4 작성

* feat: 회원가입 완료 후 index.html로 이동하도록 변경

* docs: 요구사항 5 README.md에 작성

* feat: 요청 uri이 static resource인지를 확인하는 기능 생성

* feat: stylesheet 등 다양한 형식의 파일을 지원하도록 변경

* feat: Http Response 분리

* test: SimpleHttRequest에 대한 Test 작성

* test: HttpResponse에 대한 Test 작성

* refactor: HttpServlet 및 UserController 생성

* feat: DispatcherServlet 생성

* feat: ThreadPool 사용

* docs: 구현 내용 정리

* docs: 2단계 리팩토링 목록 작성

* refactor: AbstractController 수정
- 지원하지 않는 메서드에 대해서는 MethodNotAllowed 응답 반환

* refactor: resource 처리 영역과 아닌 영역을 구분

* test: 다양한 resource postfix 형식에 대한 테스트 작성

Co-authored-by: jaeju.jang <jjj0611@gmail.com>
Co-authored-by: Jang Jaeju <44603719+jjj0611@users.noreply.github.com>

* docs: 3단계 요구사항3 구현 기능 목록 작성

* feat: HttpSession 인터페이스 작성

* feat: SimpleHttpSession 구현체 작성

* feat: httpSession을 적용하여 로그인 구현

* feat: Cookie 객체 분리

* refactor: Cookies 생성

* refactor: 지원하지 않는 메서드에 대해서 MethodNotAllowed를 응답하도록 변경

* refactor: 테스트용 request 파일명 변경

* test: UserServiceTest#findAll 테스트 작성

* refactor: HttpVersion 객체 분리

* docs : 3단계 리팩터링 목록 작성

* refactor : 인코딩 실패 시 errorStack 출력 -> InternalServerError 반환

* refactor : null 반환 제거

* refactor : doGet() 템플릿화하어 재사용 가능한 구조를 만들기

* refactor : 로그인 검증에 대한 부분을 분리하여 재사용 가능하도록 변경

Co-authored-by: 또링 <jnsorn@gmail.com>
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.

None yet

2 participants