-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
리뷰 빠르게 반영해주셨네요! 테스트가 없어서 아쉽네요, 추후에 꼭 추가해주세요! 고생하셨습니다~
리뷰 빠르게 반영해주셨네요! 테스트가 없어서 아쉽네요, 추후에 꼭 추가해주세요! 고생하셨습니다~
- Loading branch information
1 parent
3152d3d
commit 1ae5770
Showing
39 changed files
with
643 additions
and
581 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
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,22 @@ | ||
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 CacheControl cacheControl = CacheControl.noCache() | ||
.cachePrivate(); | ||
|
||
final WebContentInterceptor webContentInterceptor = new WebContentInterceptor(); | ||
webContentInterceptor.addCacheMapping(cacheControl, "/**"); | ||
|
||
registry.addInterceptor(webContentInterceptor); | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
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,18 @@ | ||
package cache.com.example.etag; | ||
|
||
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"); | ||
filterRegistrationBean.addUrlPatterns("/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
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 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 |
---|---|---|
@@ -1,29 +1,11 @@ | ||
package nextstep; | ||
|
||
import nextstep.jwp.HandlerResolver; | ||
import nextstep.jwp.JwpHttpDispatcher; | ||
import nextstep.jwp.SessionManager; | ||
import nextstep.jwp.handler.get.LoginGetHandler; | ||
import nextstep.jwp.handler.get.RegisterGetHandler; | ||
import nextstep.jwp.handler.get.RootGetHandler; | ||
import nextstep.jwp.handler.post.LoginPostHandler; | ||
import nextstep.jwp.handler.post.RegisterPostHandler; | ||
import org.apache.catalina.startup.Tomcat; | ||
import org.apache.coyote.http11.Handler; | ||
import java.util.Map; | ||
|
||
public class Application { | ||
|
||
private static final Map<String, Handler> httpGetHandlers = | ||
Map.of("/", new RootGetHandler(), | ||
"/login", new LoginGetHandler(new SessionManager()), | ||
"/register", new RegisterGetHandler()); | ||
private static final Map<String, Handler> httpPostHandlers = | ||
Map.of("/login", new LoginPostHandler(new SessionManager()), | ||
"/register", new RegisterPostHandler()); | ||
|
||
public static void main(final String[] args) { | ||
final var tomcat = new Tomcat(new JwpHttpDispatcher(new HandlerResolver(httpGetHandlers, httpPostHandlers))); | ||
final var tomcat = new Tomcat(); | ||
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,29 @@ | ||
package nextstep.jwp; | ||
|
||
import nextstep.jwp.controller.Controller; | ||
import org.apache.coyote.http11.ContentType; | ||
import org.apache.coyote.http11.HttpServlet; | ||
import org.apache.coyote.http11.StatusCode; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class DispatcherServlet implements HttpServlet { | ||
|
||
private static final HandlerMapping handlerMapping = new HandlerMapping(); | ||
|
||
@Override | ||
public void service(final HttpRequest httpRequest, final HttpResponse httpResponse) { | ||
final Controller controller = handlerMapping.findController(httpRequest.getPath()); | ||
if (controller == null) { | ||
generateNotFoundController(httpResponse); | ||
return; | ||
} | ||
controller.service(httpRequest, httpResponse); | ||
} | ||
|
||
private void generateNotFoundController(final HttpResponse response) { | ||
response.setStatusCode(StatusCode.NOT_FOUND) | ||
.setContentType(ContentType.HTML) | ||
.setRedirect("/404.html"); | ||
} | ||
} |
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,19 @@ | ||
package nextstep.jwp; | ||
|
||
import nextstep.jwp.controller.Controller; | ||
import nextstep.jwp.controller.LoginController; | ||
import nextstep.jwp.controller.RegisterController; | ||
import nextstep.jwp.controller.RootGetController; | ||
import java.util.Map; | ||
|
||
public class HandlerMapping { | ||
|
||
private static final Map<String, Controller> controllers = | ||
Map.of("/", new RootGetController(), | ||
"/login", new LoginController(), | ||
"/register", new RegisterController()); | ||
|
||
public Controller findController(final String path) { | ||
return controllers.get(path); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.