-
Notifications
You must be signed in to change notification settings - Fork 309
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
[톰캣 구현하기 - 2, 3, 4단계] 밀리(김미성) 미션 제출합니다. #464
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5df63b5
feat: cookie, session 구현
miseongk 48cbbcb
refactor: Http Request 파싱 로직 리팩토링
miseongk ff83680
refactor: Controller 인터페이스 리팩토링
miseongk 31e04ec
refactor: HttpResponseGenerator로 응답 메세지 생성하도록 수정
miseongk 3875923
refactor: FrontController 도입하여 양방향 의존성 제거
miseongk 8c10341
test: cache 학습 테스트 작성
miseongk e2954d3
test: thread 학습 테스트 작성
miseongk d116e7d
feat: Executors로 Thread Pool 적용
miseongk 6c0f823
feat: 동시성 컬렉션으로 변경
miseongk 7cd3cb3
refactor: RequestBody 파싱 타입 변경
miseongk 835363e
docs: 기능 요구사항 작성
miseongk e054cf7
refactor: content-length 헤더 세팅 컨트롤러에서 하도록 수정
miseongk f442b98
refactor: 코드 가독성 개선
miseongk c7129d4
refactor: static resource 요청을 처리하는 StaticController 구현
miseongk b1f0506
refactor: 세션 책임 분리
miseongk 9c964f6
refactor: FrontController를 RequestMapping으로 변경
miseongk 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 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
5 changes: 5 additions & 0 deletions
5
study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java
This file contains 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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.mvc.WebContentInterceptor; | ||
|
||
@Configuration | ||
public class CacheWebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addInterceptors(final InterceptorRegistry registry) { | ||
final WebContentInterceptor interceptor = new WebContentInterceptor(); | ||
interceptor.addCacheMapping(CacheControl.noCache().cachePrivate(), "/*"); | ||
registry.addInterceptor(interceptor); | ||
} | ||
} |
19 changes: 15 additions & 4 deletions
19
study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java
This file contains 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 |
---|---|---|
@@ -1,12 +1,23 @@ | ||
package cache.com.example.etag; | ||
|
||
import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; | ||
|
||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.filter.ShallowEtagHeaderFilter; | ||
|
||
@Configuration | ||
public class EtagFilterConfiguration { | ||
|
||
// @Bean | ||
// public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
// return null; | ||
// } | ||
@Bean | ||
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
final FilterRegistrationBean<ShallowEtagHeaderFilter> filterRegistrationBean = new FilterRegistrationBean<>( | ||
new ShallowEtagHeaderFilter()); | ||
filterRegistrationBean.addUrlPatterns( | ||
"/etag", | ||
PREFIX_STATIC_RESOURCES + "/*" | ||
); | ||
return filterRegistrationBean; | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -7,3 +7,6 @@ server: | |
max-connections: 1 | ||
threads: | ||
max: 2 | ||
compression: | ||
enabled: true | ||
min-response-size: 10 |
This file contains 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package nextstep; | ||
|
||
import nextstep.jwp.JwpRequestMapping; | ||
import org.apache.catalina.startup.Tomcat; | ||
import org.apache.coyote.handler.RequestMapping; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
final var tomcat = new Tomcat(); | ||
private static final RequestMapping requestMapping = new JwpRequestMapping(); | ||
|
||
public static void main(final String[] args) { | ||
final var tomcat = new Tomcat(requestMapping); | ||
tomcat.start(); | ||
} | ||
} |
This file contains 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,37 @@ | ||
package nextstep.jwp; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import nextstep.jwp.controller.IndexController; | ||
import nextstep.jwp.controller.LoginController; | ||
import nextstep.jwp.controller.RegisterController; | ||
import nextstep.jwp.controller.StaticController; | ||
import org.apache.coyote.handler.Controller; | ||
import org.apache.coyote.handler.RequestMapping; | ||
|
||
public class JwpRequestMapping implements RequestMapping { | ||
|
||
private static final String STATIC_RESOURCE_KEY = "static"; | ||
private static final String EXTENSION_DELIMITER = "."; | ||
|
||
private final Map<String, Controller> handlerMapping = new HashMap<>(); | ||
|
||
public JwpRequestMapping() { | ||
handlerMapping.put(STATIC_RESOURCE_KEY, new StaticController()); | ||
handlerMapping.put("/", new IndexController()); | ||
handlerMapping.put("/login", new LoginController()); | ||
handlerMapping.put("/register", new RegisterController()); | ||
} | ||
|
||
@Override | ||
public Controller getHandler(final String requestUri) { | ||
if (isFileRequest(requestUri)) { | ||
return handlerMapping.get(STATIC_RESOURCE_KEY); | ||
} | ||
return handlerMapping.get(requestUri); | ||
} | ||
|
||
private boolean isFileRequest(final String requestUri) { | ||
return requestUri.contains(EXTENSION_DELIMITER); | ||
} | ||
} |
13 changes: 8 additions & 5 deletions
13
tomcat/src/main/java/nextstep/jwp/controller/IndexController.java
This file contains 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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import handler.Controller; | ||
import org.apache.coyote.handler.AbstractController; | ||
import org.apache.coyote.http11.HttpRequest; | ||
import org.apache.coyote.http11.HttpResponse; | ||
import org.apache.coyote.http11.HttpStatusCode; | ||
import org.apache.coyote.http11.ViewResolver; | ||
|
||
public class IndexController implements Controller { | ||
public class IndexController extends AbstractController { | ||
|
||
@Override | ||
public String run(final HttpRequest httpRequest, final HttpResponse httpResponse) { | ||
httpResponse.setStatusCode(HttpStatusCode.OK); | ||
return "/index.html"; | ||
public void doGet(final HttpRequest request, final HttpResponse response) { | ||
final String responseBody = ViewResolver.read("/index.html"); | ||
response.setResponseBody(responseBody); | ||
response.setContentLength(); | ||
response.setStatusCode(HttpStatusCode.OK); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한가지만 더 질문을 드리고 싶은데요,
ContentLength는 ResponseBody가 정해짐에 따라 항상 함께 정해져야 하는 것 아닐까요?
즉 이렇게 setResponseBody 이후에 setContentLength를 해주는 게 아니라 setResponseBody 내부에서 setContentLength를 처리해 주는 것은 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오!! 저도 이 부분에 대해서 고민을 했었어요!
항상 함께 정해져야 하는게 맞는 것 같다가도, responseBody를 set하는데 Content-Length가 지정될 지 예측을 할 수 있을까? 하는 생각에 그냥 분리했습니다! 당연히 http에 대해서 잘 안다면 content-length가 지정될 수 있겠구나 생각은 할 수 있겠지만요.
내부 코드를 보지 않으면 content-length가 두 번 지정될 수도 있을 것도 같네요.
그런데 해당 메서드를 사용하는 사용자 입장에서 무엇이 더 편할지는 또 고민이 되네요..
말랑은 어떻게 생각하시나요?!