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

Merged
merged 8 commits into from
Sep 12, 2020

Conversation

ksy90101
Copy link

안녕하세요!
한가지 궁금한 사항이 있습니다.

Body가 없을때 (예를 들면 get요청)같은 경우에는 null로 처리하는것이 좋을까요? 아니면 빈 맵으로 처리하는게 좋을까요?

답변이 궁금합니다 ㅠㅠ 잘 부탁드립니다 👍

@ksy90101 ksy90101 changed the base branch from master to ksy90101 September 11, 2020 10:54
Copy link

@hongsii hongsii left a comment

Choose a reason for hiding this comment

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

안녕하세요~ 럿고!
1단계 요구사항을 잘 구현해주셨네요! 👍
몇 가지 피드백을 남겼으니, 다음 단계를 진행하시면서 같이 반영해주세요~!

public class StaticController implements Controller {
@Override
public void service(Request request, DataOutputStream dos) throws IOException, URISyntaxException {
String requestUrl = request.getRequestLine().getUrl();
Copy link

Choose a reason for hiding this comment

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

규칙 4. 한 줄에 한 점만 사용 을 지키도록 수정해보면 어떨까요?

Comment on lines +16 to +22
public void service(Request request, DataOutputStream dos) {
if (request.isMethod(GET)) {
doGet(request, dos);
} else if (request.isMethod(POST)) {
doPost(request, dos);
}
}
Copy link

Choose a reason for hiding this comment

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

새로운 API가 추가된다면 해당 로직이 중복해서 생길 것 같습니다. 추상화를 통해 중복이 생기지 않도록 리팩토링해보면 어떨까요?

Comment on lines +26 to +27
QueryParams queryParams = new QueryParams(requestUrl);
Map<String, String> queryParamsMap = queryParams.getQueryParams();
Copy link

Choose a reason for hiding this comment

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

객체에서 값을 꺼내서 처리하지 않고, 일급 컬렉션 객체인 QueryParams 에게 물어보도록 바꿔보면 어떨까요?

추가로 현재 QueryParams 가 필요하면 매번 사용하는 곳에서 직접 객체를 생성해야 합니다.
Request 가 들어오면 쿼리 여부에 따라 자동으로 생성하도록 바꿔보면 어떨까요?


import http.Request;

public interface Controller {
Copy link

Choose a reason for hiding this comment

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

인터페이스 설계 👍

Map<String, String> result = new HashMap<>();
for (String token : tokens) {
String[] value = token.split(BODY_DELIMITER);
result.put(value[0], value[1]);
Copy link

Choose a reason for hiding this comment

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

key= 와 같이 값을 비워서 요청하면 어떻게 될까요?
예외 케이스에 대해서도 적절히 고민해보시면 좋을 것 같아요~!

import http.Request;

public interface Controller {
void service(Request request, DataOutputStream dos) throws IOException, URISyntaxException;
Copy link

Choose a reason for hiding this comment

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

응답 객체도 만들어 보면 어떨까요?

Comment on lines +9 to +13
private RequestMethod method;

private String url;

private String protocol;
Copy link

Choose a reason for hiding this comment

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

Request-Line 의 각 요소는 아래와 같이 부릅니다~!

Request-Line = Method SP Request-URI SP HTTP-Version CRLF

class QueryParamsTest {

@Test
void name() {
Copy link

Choose a reason for hiding this comment

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

테스트 메서드명을 바꾸시는 것을 깜빡하셨네요~!

String requestUrl = request.getRequestLine().getUrl();

byte[] body = FileIoUtils.loadFileFromClasspath(Directory.TEMPLATES.getDirectory() + requestUrl);
ContentType contentType = ContentType.of(requestUrl);
Copy link

@hongsii hongsii Sep 12, 2020

Choose a reason for hiding this comment

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

ContentType 이 필요한 곳 마다 같은 로직을 따로 처리하고 있습니다. Request 객체로 메시지를 보내도록 바꿔보면 어떨까요?

import controller.UserCreateController;
import http.ContentType;

public class RequestMapping {
Copy link

Choose a reason for hiding this comment

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

RequestMapping, Controller 등 테스트 코드가 작성되지 않은 클래스가 있던데 테스트 코드를 작성해보면 어떨까요?

@hongsii hongsii merged commit 9cd5039 into woowacourse:ksy90101 Sep 12, 2020
hongsii pushed a commit that referenced this pull request Oct 17, 2020
* [럿고] 1단계 - HTTP 웹 서버 구현 미션 제출합니다. (#101)

* docs: README.md 작성

* feat: URL추출 메서드 및 request header 출력 메서드 작성

* feat: /index.html로 접속했을 때 index.html 파일 응답 구현

* feat: 회원가입 시 회원에 대한 정보를 서버에 저장하는 로직 구현

* feat: post 처리 및 요청 값 객체 생성

* feat: 요구사항3 완료

* feat: 302 response 구현

* refactor: 요청에 따른 응답을 컨트롤러로 처리하도록 수정

Co-authored-by: 황준호 <42054054+hwanghe159@users.noreply.github.com>

* refactor: response 객체 생성

* refactor: header line 추가

* refactor: 필드명 변경, 디미터법칙 따르도록 수정

* refactor: 필드명 변경, RequestBody에 대한 예외처리, stringBuilder에서 append사용

* refactor: service 메서드 추상화

* refactor: QueryParams를 Request 내부로 이동, RequestUri, Path 생성

* feat: 쓰레드풀 적용

* refactor: / 경로 index.html 이동 controller 생성 및 전체 리팩토링

* test: Response에 대한 test작성

* test: controller 테스트 추가

* refactor: 파일 대문자 소문자로 변경

* test: 테스트 fail 해결, request, response파일 추가

* refactor: 지원하는 않는 메서드 예외 처리 리팩토링

* refactor: 리팩토링

- Header enum 삭제
- 컨트롤러 접근제어자 변경
- IllegalRequestException 메시지 변경
- 상수 이름 변경

* refactor: response test를 ByteArrayOutputStream으로 변경

Co-authored-by: SeYun <53366407+ksy90101@users.noreply.github.com>
Co-authored-by: SeYun <ksy90101@naver.com>
hongsii pushed a commit that referenced this pull request Nov 2, 2020
* [그래] 1단계 - HTTP 웹 서버 구현 미션 제출합니다. (#102)

* docs: README.md 작성

* feat: URL추출 메서드 및 request header 출력 메서드 작성

* feat: /index.html로 접속했을 때 index.html 파일 응답 구현

* feat: 회원가입 시 회원에 대한 정보를 서버에 저장하는 로직 구현

* feat: post 처리 및 요청 값 객체 생성

* feat: 요구사항3 완료

* feat: 302 response 구현

* refactor: 요청에 따른 응답을 컨트롤러로 처리하도록 수정

Co-authored-by: SeYun <ksy90101@naver.com>

* [그래] 2단계 - HTTP 웹 서버 리팩토링 미션 제출합니다. (#150)

* [럿고] 1단계 - HTTP 웹 서버 구현 미션 제출합니다. (#101)

* docs: README.md 작성

* feat: URL추출 메서드 및 request header 출력 메서드 작성

* feat: /index.html로 접속했을 때 index.html 파일 응답 구현

* feat: 회원가입 시 회원에 대한 정보를 서버에 저장하는 로직 구현

* feat: post 처리 및 요청 값 객체 생성

* feat: 요구사항3 완료

* feat: 302 response 구현

* refactor: 요청에 따른 응답을 컨트롤러로 처리하도록 수정

Co-authored-by: 황준호 <42054054+hwanghe159@users.noreply.github.com>

* refactor: response 객체 생성

* refactor: header line 추가

* refactor: 필드명 변경, 디미터법칙 따르도록 수정

* refactor: 필드명 변경, RequestBody에 대한 예외처리, stringBuilder에서 append사용

* refactor: service 메서드 추상화

* refactor: QueryParams를 Request 내부로 이동, RequestUri, Path 생성

* feat: 쓰레드풀 적용

* refactor: / 경로 index.html 이동 controller 생성 및 전체 리팩토링

* test: Response에 대한 test작성

* test: controller 테스트 추가

* refactor: 파일 대문자 소문자로 변경

* test: 테스트 fail 해결, request, response파일 추가

* refactor: 지원하는 않는 메서드 예외 처리 리팩토링

* refactor: 리팩토링

- Header enum 삭제
- 컨트롤러 접근제어자 변경
- IllegalRequestException 메시지 변경
- 상수 이름 변경

* refactor: response test를 ByteArrayOutputStream으로 변경

Co-authored-by: SeYun <53366407+ksy90101@users.noreply.github.com>
Co-authored-by: SeYun <ksy90101@naver.com>

* docs: 2단계, 3단계 요구사항 작성

* feat: 로그인 기능 구현

* feat: 로그인 시 user/list를 접속할 수 있게 기능 구현

* feat: 로그아웃, 세션 기능 구현

* feat: 피드백 반영

* refactor: request에 session 추가

* refactor: response에 cookies 추가

* refactor: session의 attribute 값으로 로그인 검증

Co-authored-by: 황준호 <42054054+hwanghe159@users.noreply.github.com>
hongsii pushed a commit that referenced this pull request Nov 21, 2020
* [럿고] 1단계 - HTTP 웹 서버 구현 미션 제출합니다. (#101)

* docs: README.md 작성

* feat: URL추출 메서드 및 request header 출력 메서드 작성

* feat: /index.html로 접속했을 때 index.html 파일 응답 구현

* feat: 회원가입 시 회원에 대한 정보를 서버에 저장하는 로직 구현

* feat: post 처리 및 요청 값 객체 생성

* feat: 요구사항3 완료

* feat: 302 response 구현

* refactor: 요청에 따른 응답을 컨트롤러로 처리하도록 수정

Co-authored-by: 황준호 <42054054+hwanghe159@users.noreply.github.com>

* [럿고] 2단계 - HTTP 웹 서버 리팩토링 미션 제출합니다. (#149)

* [그래] 1단계 - HTTP 웹 서버 구현 미션 제출합니다. (#102)

* docs: README.md 작성

* feat: URL추출 메서드 및 request header 출력 메서드 작성

* feat: /index.html로 접속했을 때 index.html 파일 응답 구현

* feat: 회원가입 시 회원에 대한 정보를 서버에 저장하는 로직 구현

* feat: post 처리 및 요청 값 객체 생성

* feat: 요구사항3 완료

* feat: 302 response 구현

* refactor: 요청에 따른 응답을 컨트롤러로 처리하도록 수정

Co-authored-by: SeYun <ksy90101@naver.com>

* refactor: response 객체 생성

* refactor: header line 추가

* refactor: 필드명 변경, 디미터법칙 따르도록 수정

* refactor: 필드명 변경, RequestBody에 대한 예외처리, stringBuilder에서 append사용

* refactor: service 메서드 추상화

* refactor: QueryParams를 Request 내부로 이동, RequestUri, Path 생성

* feat: 쓰레드풀 적용

* refactor: / 경로 index.html 이동 controller 생성 및 전체 리팩토링

* test: Response에 대한 test작성

* test: controller 테스트 추가

* refactor: 파일 대문자 소문자로 변경

* test: 테스트 fail 해결, request, response파일 추가

* refactor: 지원하는 않는 메서드 예외 처리 리팩토링

* refactor: 리팩토링

- Header enum 삭제
- 컨트롤러 접근제어자 변경
- IllegalRequestException 메시지 변경
- 상수 이름 변경

* refactor: response test를 ByteArrayOutputStream으로 변경

Co-authored-by: 황준호 <42054054+hwanghe159@users.noreply.github.com>

* docs: 2단계, 3단계 요구사항 작성

* feat: 로그인 기능 구현

* feat: 로그인 시 user/list를 접속할 수 있게 기능 구현

* feat: 로그아웃, 세션 기능 구현

* feat: 피드백 반영

* refactor: 필요없는 파일 제거

* refactor: Handlebars 한번 초기화해서 재사용

* refactor: static변수 이름 변경, 인스턴스 변수 이름 변경

* refactor: 리팩토링

- 리퀘스트 바디 String -> Map 파싱 로직 캡슐화
- Database -> UserRepository 이름변경

* refactor: HttpHeaders 구성 로직 이동

* refactor: Cookie 생성

Co-authored-by: SeYun <53366407+ksy90101@users.noreply.github.com>
Co-authored-by: SeYun <ksy90101@naver.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

3 participants