-
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
[톰캣 구현하기 - 3, 4단계] 로이스(원태연) 미션 제출합니다. #429
Changes from all commits
75b2629
996e112
a75db6e
96d3b70
15c2edc
4ac9370
59526f4
022251f
bcbe17d
0370d81
d13d207
88e9075
3659b63
e182bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
public class CacheControlInterceptor implements HandlerInterceptor { | ||
|
||
@Override | ||
public void afterCompletion( | ||
final HttpServletRequest request, | ||
final HttpServletResponse response, | ||
final Object handler, | ||
final Exception ex | ||
) { | ||
final String cacheControl = CacheControl | ||
.noCache() | ||
.cachePrivate() | ||
.getHeaderValue(); | ||
response.setHeader(HttpHeaders.CACHE_CONTROL, cacheControl); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
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() { | ||
FilterRegistrationBean<ShallowEtagHeaderFilter> filterRegistrationBean = | ||
new FilterRegistrationBean<>(new ShallowEtagHeaderFilter()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ETag를 생성한 뒤 응답에 포함시켜 반환합니다! |
||
filterRegistrationBean.addUrlPatterns("/etag"); | ||
filterRegistrationBean.addUrlPatterns("/resources/*"); | ||
return filterRegistrationBean; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package nextstep.web; | ||
|
||
import org.apache.coyote.http11.mvc.AbstractController; | ||
import org.apache.coyote.http11.mvc.view.ResponseEntity; | ||
import org.apache.coyote.http11.controller.AbstractController; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class HelloController extends AbstractController { | ||
|
||
@Override | ||
public ResponseEntity handleGetRequest(final HttpRequest request, final HttpResponse response) { | ||
return ResponseEntity.fromSimpleStringData("Hello world!"); | ||
public void doGet(final HttpRequest request, final HttpResponse response) { | ||
response.textPlain("Hello world!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package nextstep.web; | ||
|
||
import org.apache.coyote.http11.mvc.AbstractController; | ||
import org.apache.coyote.http11.mvc.view.ResponseEntity; | ||
import org.apache.coyote.http11.controller.AbstractController; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class IndexController extends AbstractController { | ||
|
||
@Override | ||
public ResponseEntity handleGetRequest(final HttpRequest request, final HttpResponse response) { | ||
return ResponseEntity.forwardTo("/index.html"); | ||
public void doGet(final HttpRequest request, final HttpResponse response) { | ||
response.forwardTo("/index.html"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
package org.apache.catalina.connector; | ||
|
||
import org.apache.coyote.http11.Http11Processor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
import org.apache.coyote.http11.Http11Processor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Connector implements Runnable { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(Connector.class); | ||
|
||
private static final int DEFAULT_PORT = 8080; | ||
private static final int DEFAULT_ACCEPT_COUNT = 100; | ||
private static final int DEFAULT_MAX_THREAD_COUNT = 250; | ||
|
||
private final ServerSocket serverSocket; | ||
private final Executor executor; | ||
private boolean stopped; | ||
|
||
public Connector() { | ||
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT); | ||
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT, DEFAULT_MAX_THREAD_COUNT); | ||
} | ||
|
||
public Connector(final int port, final int acceptCount) { | ||
public Connector(final int port, final int acceptCount, final int maxThreadCount) { | ||
this.serverSocket = createServerSocket(port, acceptCount); | ||
this.stopped = false; | ||
this.executor = Executors.newFixedThreadPool(maxThreadCount); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 설정하면 내부적으로 스레드가 어떻게 관리되나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 설정한 개수(250) 만큼의 |
||
} | ||
|
||
private ServerSocket createServerSocket(final int port, final int acceptCount) { | ||
|
@@ -67,7 +71,7 @@ private void process(final Socket connection) { | |
return; | ||
} | ||
var processor = new Http11Processor(connection); | ||
new Thread(processor).start(); | ||
executor.execute(processor); | ||
} | ||
|
||
public void stop() { | ||
|
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.
no-cache와 no-store
private과 public 각각 어떤 차이가 있었나요?
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.
모두 응답 헤더 Cache-control에 설정하여 캐시에 대한 정책에 대해 명시하는 것 입니다.
no-cache
는 캐시를 저장은 해도 되지만, 매 요청마다 revalidate(재검증..?)가 필요하다는 정책이고no-store
는 캐시를 아예 저장하지 말라는 뜻입니다.private
과public
의 차이점은 캐싱의 범위입니다. CDN이나 다른 proxy 서버에 캐싱을 저장할 수 있는 public과 달리, private은 클라이언트에서만 캐싱할 수 있습니다.이미지나 로고 같이 모든 사용자에게 보여지는 민감하지 않은 정보는 public, 사용자와 관련된 데이터는 private으로 설정하는 식으로 목적에 맞게 관리 할 수 있을 것 같습니다!