-
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단계] 엔델(김민준) 미션 제출합니다. (#331)
* feat: 1단계 - HTTP 서버 구현하기 1. GET /index.html 응답하기 2. CSS 지원하기 3. Query String 파싱 * feat: 2단계 - 로그인 구현하기 1. HTTP Status Code 302 2. POST 방식으로 회원가입 3. Cookie에 JSESSIONID 값 저장하기 4. Session 구현하기 * test: 테스트를 통과하도록 수정 * test: 학습 테스트 작성 * refactor: BufferedReader를 try with resource에 넣기 * refactor: HttpHeaders를 클래스로 변경 * refactor: HttpStatus를 열거로 변경 * style: final 추가 * feat: 로그인을 post 방식으로 변경 * refactor: enum의 valueOf를 of로 네이밍 변경, ContentType을 enum으로 변경 * refactor: 빈 Cookie인 경우 .empty() 메서드를 사용해 생성하도록 메서드 네이밍 변경
- Loading branch information
Showing
13 changed files
with
447 additions
and
19 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
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,28 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Configuration | ||
public class CacheWebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addInterceptors(final InterceptorRegistry registry) { | ||
registry.addInterceptor(new NestedInterceptor()); | ||
} | ||
|
||
class NestedInterceptor implements HandlerInterceptor { | ||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
response.addHeader(HttpHeaders.CACHE_CONTROL, "no-cache"); | ||
response.addHeader(HttpHeaders.CACHE_CONTROL, "private"); | ||
return true; | ||
} | ||
} | ||
} |
16 changes: 12 additions & 4 deletions
16
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,20 @@ | ||
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> filterFilterRegistrationBean = new FilterRegistrationBean<>(); | ||
filterFilterRegistrationBean.setFilter(new ShallowEtagHeaderFilter()); | ||
filterFilterRegistrationBean.addUrlPatterns("/etag"); | ||
filterFilterRegistrationBean.addUrlPatterns("/resources-versioning/*"); | ||
filterFilterRegistrationBean.setOrder(1); | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.apache.http; | ||
|
||
public enum ContentType { | ||
|
||
HTML("text/html;charset=utf-8"), | ||
CSS("text/css"), | ||
JS("application/javascript"), | ||
ICO("image/x-icon"); | ||
|
||
private static final ContentType[] VALUES; | ||
|
||
static { | ||
VALUES = values(); | ||
} | ||
|
||
ContentType(final String value) { | ||
this.value = value; | ||
} | ||
|
||
private final String value; | ||
|
||
public String getValue() { | ||
return this.value; | ||
} | ||
|
||
public static ContentType of(final String fileExtension) { | ||
final ContentType contentType = resolve(fileExtension); | ||
if (contentType == null) { | ||
throw new IllegalArgumentException(); | ||
} | ||
return contentType; | ||
} | ||
|
||
private static ContentType resolve(final String fileExtension) { | ||
for (final ContentType contentType : VALUES) { | ||
if (contentType.name().equalsIgnoreCase(fileExtension)) { | ||
return contentType; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.