-
Notifications
You must be signed in to change notification settings - Fork 310
[톰캣 구현하기 - 3, 4단계] 푸우(백승준) 미션 제출합니다. #446
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
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7cfe069
chore: HttpResponse -> ResponseEntity 변경
BGuga 58a60ff
feat: StatusLine 객체 생성
BGuga 6a56819
feat: ResponseHeaders 객체 생성
BGuga 0fb84e6
feat: HttpResponse 객체 생성
BGuga 93fa845
feat: HttpResponse 가 Response 를 만든다.
BGuga f3f2cc1
chore: Headers 네이밍 변경
BGuga 90c7469
feat: AbstractController 생성
BGuga 80c54d5
refactor: login 요청에 대한 LoginController 생성
BGuga 3784039
refactor: register 요청에 대한 SignUpController 생성
BGuga 65eba7e
feat: Thread Pool 적용
BGuga 473c173
feat: SessionManager 에 ConcurrentHashMap 적용
BGuga 4aae70f
fix: Content-Type, Content-Length 헤더 값에 : 제거
BGuga 6f2a563
test: HttpResponse 테스트 추가
BGuga b672c07
test: 통합 테스트 추가
BGuga d3804c5
feat: ResponseEntity 에 redirect 메서드 생성
BGuga fdae1b2
fix: notAllowed ResponseEntity 에 빈 Map 추가
BGuga df7b7ae
refactor: AbstractController 에서 notAllowed 를 정의하도록 변경
BGuga 1ff493e
refactor: AbstractController 메서드 protected 설정
BGuga 264a343
chore: 상수와 인스턴스 변수 간의 공백 추가
BGuga cd6d5d9
refactor: CoreSize, maxThread 개수 변경
BGuga 9786a30
refactor: Controller 인터페이스 수정
BGuga 6e883bd
feat: Connector 코어사이즈, keep-alive 시간 변경
BGuga eb26d4a
refactor: ResponseBuilder location, sessionCookie 기능 추가 및 상수 분리
BGuga 867bc28
refactor: RequestHeaders Content-Length 추가
BGuga 6791dbf
refactor: Http 표준 스펙에 맞춘 응답을 생성하는 HttpREsponseConverter 생성
BGuga e861aa3
refactor: Http 표준 스펙에 맞춘 응답을 생성하는 HttpREsponseConverter 생성
BGuga 5813104
refactor: getter 대신 메시지를 던지도록 변경
BGuga 21e6e10
fix: Content-Length 상수 은닉
BGuga cb1c4f6
refactor: 사용하지 않는 getter 삭제 및 내부 필드 은닉화
BGuga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tomcat/src/main/java/org/apache/coyote/http11/HttpResponseConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.StringJoiner; | ||
import java.util.stream.Collectors; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
import org.apache.coyote.http11.response.HttpResponseHeaders; | ||
import org.apache.coyote.http11.response.HttpStatusCode; | ||
import org.apache.coyote.http11.response.ResponseBody; | ||
import org.apache.coyote.http11.response.StatusLine; | ||
|
||
public class HttpResponseConverter { | ||
|
||
private static final String HTTP_VERSION = "HTTP/1.1"; | ||
|
||
private HttpResponseConverter() { | ||
} | ||
|
||
public static String convert(HttpResponse httpResponse) { | ||
BGuga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
StringJoiner responseJoiner = new StringJoiner(System.lineSeparator()); | ||
responseJoiner.add(extractStatusLine(httpResponse.getStatusLine())); | ||
responseJoiner.add(extractHeaders(httpResponse.getHeaders())); | ||
responseJoiner.add(System.lineSeparator()); | ||
addBody(responseJoiner, httpResponse.getBody()); | ||
return responseJoiner.toString(); | ||
} | ||
|
||
private static String extractStatusLine(StatusLine statusLine) { | ||
HttpStatusCode httpStatusCode = statusLine.getHttpStatusCode(); | ||
return HTTP_VERSION + " " + httpStatusCode.getStatusCode() + " " + httpStatusCode.name(); | ||
} | ||
|
||
private static String extractHeaders(HttpResponseHeaders headers) { | ||
Map<String, String> headerValues = headers.getHeaders(); | ||
return headerValues.keySet() | ||
.stream() | ||
.map(headerName -> makeHeader(headerName, headerValues.get(headerName))) | ||
.collect(Collectors.joining(System.lineSeparator())); | ||
} | ||
|
||
private static String makeHeader(String headerName, String value) { | ||
return headerName + ": " + value; | ||
} | ||
|
||
private static void addBody(StringJoiner responseJoiner, ResponseBody body) { | ||
Optional<String> responseBody = body.getValue(); | ||
if (responseBody.isPresent()) { | ||
responseJoiner.add(responseBody.get()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tomcat/src/main/java/org/apache/coyote/http11/controller/AbstractController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.apache.coyote.http11.controller; | ||
|
||
import org.apache.coyote.http11.request.HttpMethod; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
import org.apache.coyote.http11.response.ResponseEntity; | ||
|
||
public abstract class AbstractController implements Controller { | ||
|
||
|
||
@Override | ||
public void service(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
if (httpRequest.isRequestOf(HttpMethod.GET)) { | ||
doGet(httpRequest, httpResponse); | ||
return; | ||
} | ||
if (httpRequest.isRequestOf(HttpMethod.POST)) { | ||
doPost(httpRequest, httpResponse); | ||
return; | ||
} | ||
if (httpRequest.isRequestOf(HttpMethod.PUT)) { | ||
doPut(httpRequest, httpResponse); | ||
return; | ||
} | ||
if (httpRequest.isRequestOf(HttpMethod.DELETE)) { | ||
doDelete(httpRequest, httpResponse); | ||
return; | ||
} | ||
throw new UnsupportedOperationException( | ||
"해당 HttpMethod 는 아직 지원하지 않습니다." + httpRequest.getRequestLine().getMethod()); | ||
} | ||
|
||
protected void doGet(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.responseFrom(ResponseEntity.notAllowed()); | ||
} | ||
|
||
protected void doPost(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.responseFrom(ResponseEntity.notAllowed()); | ||
} | ||
|
||
protected void doPut(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.responseFrom(ResponseEntity.notAllowed()); | ||
} | ||
|
||
protected void doDelete(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.responseFrom(ResponseEntity.notAllowed()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.