-
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.
[1 -2단계 - Tomcat 구현하기] 카피(김상혁) 미션 제출합니다 (#536)
전체적으로 잘 해주셨습니다 👍 수정 필요한 부분은 다음단계 진행하면서 고쳐주세요 404나 500 같은 페이지도 띄워주시면 좋을것 같습니다. Http11Processor 리팩토링 기대할게요!
- Loading branch information
1 parent
0b698a2
commit e622b01
Showing
17 changed files
with
367 additions
and
44 deletions.
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
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
8 changes: 8 additions & 0 deletions
8
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,21 @@ | ||
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) { | ||
WebContentInterceptor webContentInterceptor = new WebContentInterceptor(); | ||
webContentInterceptor.addCacheMapping( | ||
CacheControl.noCache().cachePrivate(), | ||
"/**" | ||
); | ||
registry.addInterceptor(webContentInterceptor); | ||
} | ||
} |
24 changes: 20 additions & 4 deletions
24
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,28 @@ | ||
package cache.com.example.etag; | ||
|
||
import cache.com.example.version.ResourceVersion; | ||
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; | ||
|
||
import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; | ||
|
||
@Configuration | ||
public class EtagFilterConfiguration { | ||
|
||
// @Bean | ||
// public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
// return null; | ||
// } | ||
private final ResourceVersion resourceVersion; | ||
|
||
public EtagFilterConfiguration(ResourceVersion resourceVersion) { | ||
this.resourceVersion = resourceVersion; | ||
} | ||
|
||
@Bean | ||
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
FilterRegistrationBean<ShallowEtagHeaderFilter> filterFilterRegistrationBean | ||
= new FilterRegistrationBean<>(new ShallowEtagHeaderFilter()); | ||
filterFilterRegistrationBean.addUrlPatterns("/etag"); | ||
filterFilterRegistrationBean.addUrlPatterns(PREFIX_STATIC_RESOURCES + "/" + resourceVersion.getVersion() + "/*"); | ||
return filterFilterRegistrationBean; | ||
} | ||
} |
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
File renamed without changes.
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
30 changes: 30 additions & 0 deletions
30
tomcat/src/main/java/org/apache/coyote/http11/Session.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Session { | ||
|
||
private static final Map<String, Object> values = new HashMap<>(); | ||
private final String id; | ||
|
||
public Session(final String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public Object getAttribute(final String name) { | ||
return values.get(name); | ||
} | ||
|
||
public void setAttribute(final String name, final Object value) { | ||
values.put(name, value); | ||
} | ||
|
||
public void removeAttribute(final String name) { | ||
values.remove(name); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tomcat/src/main/java/org/apache/coyote/http11/SessionManager.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import org.apache.catalina.Manager; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class SessionManager implements Manager { | ||
|
||
private static final Map<String, Session> SESSIONS = new HashMap<>(); | ||
|
||
public SessionManager() { | ||
} | ||
|
||
@Override | ||
public void add(Session session) { | ||
SESSIONS.put(session.getId(), new Session(session.getId())); | ||
} | ||
|
||
@Override | ||
public Session findSession(String id) throws IOException { | ||
return SESSIONS.get(id); | ||
} | ||
|
||
@Override | ||
public void remove(Session session) { | ||
SESSIONS.remove(session.getId()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tomcat/src/main/java/org/apache/coyote/http11/controller/ResourceLoader.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.apache.coyote.http11.controller; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class ResourceLoader { | ||
|
||
public static byte[] loadResource(String resourceName) throws URISyntaxException, IOException { | ||
URL url = ResourceLoader.class.getClassLoader().getResource(resourceName); | ||
if (url == null) { | ||
throw new IllegalArgumentException("존재하지 않는 리소스 입니다." + resourceName); | ||
} | ||
|
||
Path path = Path.of(url.toURI()); | ||
return Files.readAllBytes(path); | ||
} | ||
} |
Oops, something went wrong.