Skip to content

[Hamill&Dan][HTTP 웹서버 구현하기] Step1, 2 Submit #50

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

Merged
merged 29 commits into from
Mar 24, 2020

Conversation

hanurii
Copy link

@hanurii hanurii commented Mar 20, 2020

HTTP 웹서버 구현하기

# Step 1 기능 구현 완료

  • Index 파일 읽기
  • 회원가입 구현
  • 로그인 구현
  • 사용자 목록 페이지 구현
  • Stylesheet 지원 구현

# Step 2 리팩토링

  • 메소드 분리 및 클래스 분리
    • HttpRequest, HttpResponse 객체화를 통한 리팩토링 완료

# Ground Rule

https://github.com/Hamill210/java-was/wiki/Ground-Rule

hanurii and others added 29 commits March 16, 2020 15:38
- Ground Rule 추가
- Repository 관리 추가
- 커밋 메시지 가이드 추가
refactor : README.md update
- Handlebar 수정 중

associate with : #1
- 모든 Request Header 출력하기
- Request Line에서 path 분리하기
- path에 해당하는 파일 읽어 응답하기

associate with : #1
- index.html 완료

associate with : #1
- Ground Rule wiki 로 이동
- Day 의 회고는 issue 로 관리
- 상대 경로였던 프로그램 경로를 절대 경로로 수정
- UserController 클래스 추가
- WelcomeController 클래스 추가
- HttpRequestUtils 클래스에 parseUriString 메서드 추가

associate with : #2
- WelcomeController 추가
- UserController 추가
- User 생성자 추가 (매개변수 userParameterMap)

associate with #2
- 코드 정리
- Test case 추가

associate with #2
- user/form.html 수정
* requestHeader, requestBody 메서드 추가 및 수정 중

associate with : #6
- requestBody 가져오기

associate with #6
- requestLine, requestHeader, requestBody 를 나누어 구현
- Pair 객체를 사용
- GET /user/form.html 구현
- POST /user/create 구현
  - WebServer 에 userDB 를 두어 User 정보를 관리

associate with #7, #8
- requestLine, requestHeader, requestBody 를 가져올 수 있는 메소드를 나누어 구현
- statusLine, responseHeader, responseBody 를 가져올 수 있는 메소드를 나누어 구현
- PageController
  - dowork()의 리턴타입 변경 (String -> Map)
- ReqestHandler
  - dowork() 리턴값 변경에 따른 변수명 변경

associate with : #7
- /index.html, /user/login.html 구현
- User create 연결

associate with #7
- login_failed는 GET에 추가

associate with #7
- /user/login 구현
- parseRequestBody 메서드 구현

associate with #7
- Post /user/login 구현 완료

associate with #7 #8
- RequestHandler.java : dowork()
    - requestHeader에서 cookie 값 추출 후 조건문 사용

associate with #1
- PageController.java : doWork()
  - css 처리를 위한 로직 추가
- RequestHandler.java : responseHeader()
  - Content-Type 추가

associate with #9 #10
[Hamill&Dan][HTTP 웹서버 구현하기] Step1 Submit
- HttpTemplate.java
  - HttpRequest 상속을 위한 Class 생성
- HttpRequest.java 추가
  - request 생성
- RequestHandler.java : run()
  - 로직 변경

associate with #18
- HttpRequest.java : requestHeader() 추가
- HttpRequestUtils.java : getKeyValueMap() 추가
- HttpTemplate.java
  - requestHeader type Map<String, String> 으로 변경

associate with #18
- HttpRequest.java : requestBody() 추가
  - RequestHandler.java 에 있었던 메서드를 추가하고 리팩토링

associate with #18
- PageController.java : dowork()
  - 메서드 파라미터 변경 (Map<String, String>)
  - 파라미터 변경에 따른 getValue() 삭제
- HttpRequest.java : getStartLine() 추가
 
associate with #18
- HttpResponse.java 구현 완료
- WebServer.java : getWebappPath()
  - WEB_PATH 위치 이동 및 static 선언
- HttpTemplate.java
  - 필드 변경
- PageController.java
  - protocol 누락 수정
 
associate with #18
- RequestHandler.java : sendResponse()
  - 코드 개선
 
associate with #18
[Hamill&Dan][HTTP 웹서버 구현하기] Step2 Submit
String protocol = requestLine.get("protocol");
String contentType = requestHeader.get("Accept");

switch (method) {
Copy link

@imjinbro imjinbro Mar 22, 2020

Choose a reason for hiding this comment

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

요청 url이 추가될 때마다 if ~ else if ~ else 문이 길어지겠군요
Spring mvc 처리 흐름에서 HandlerMapping / Controller 역할 구분에 대하여 학습해보시고 리팩토링 해보시길 권해드려요

users.put(user.getUserId(), user);
}
public static void addUser(User user) {
users.put(user.getUserId(), user);

Choose a reason for hiding this comment

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

User null 케이스에 대한 예외처리가 필요해보입니다.
항상 워스트 케이스를 생각하시면서 그에 대한 처리를 하시길 권해드려요

public class HttpRequest extends HttpTemplate {
private BufferedReader br;

public HttpRequest(BufferedReader br) throws Exception {

Choose a reason for hiding this comment

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

요청 데이터 읽는 방식이 파일 읽기 혹은 다른 방식으로 변경될 경우 HttpRequest 객체 코드에도 영향이 있지 않을까요?
BufferedReader를 생성자로 가지고 있다면 입력값을 읽는 방법 변경이 해당 클래스 코드에도 영향이 있을 것 입니다.
HttpRequest는 말그대로 Request에 대한 정보를 가지고 있는 객체로 한정 짓는 것이 필요합니다.

}

public String getProtocol() {
return this.startLine.get("protocol");

Choose a reason for hiding this comment

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

생성자에서 Request를 받아서 모두 쪼개어 놓으면 되지 않을까요?
그렇게 하면 예외처리도 쉬울 것 같습니다.

@honux77 honux77 merged commit 9ceda95 into code-squad:Hamill210 Mar 24, 2020
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.

4 participants