-
Notifications
You must be signed in to change notification settings - Fork 388
[3단계 - Tomcat 구현하기] 새양(양경호) 미션 제출합니다. #609
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
0a73d91
refactor: use try with resources statement to prevent memory leak
geoje 7ca7dcf
refactor: rearrange method order on request
geoje f323126
refactor: remove unused method while adding method of major header
geoje 92bceb3
refactor: use checking parameters exists with stream
geoje c657b7f
refactor: remove logging on request with session
geoje 2a81262
refactor: move responsibility to create session to manager
geoje db5648a
refactor: move responsibility to create session to manager
geoje b049dbf
refactor: simplify method lines and extract methods
geoje 2300bef
refactor: move and add enum to encapsulate primitive value
geoje f0e2106
refactor: add method enum for request encapsulation fields
geoje 9890bd4
refactor: extract constant on request and message
geoje 38ae266
refactor: use stream to reduce indent
geoje a9feb02
fix: use value of enum to fix message
geoje 4414499
test: fix failed test about cache
geoje 5cabc8d
refactor: remove excluding path
geoje ddbd91c
fix: complete cache busting of static resources
geoje f1b6c55
fix: add etag filter
geoje cf327d2
refactor: remove unused method
geoje 6d68afb
refactor: move package to common position
geoje c6513c9
refactor: optimize new line
geoje 02da74a
refactor: change new line style
geoje 190f098
refactor: extract all constant at http response
geoje 6a468c1
refactor: extract filtering method on http request
geoje 8631162
refactor: change map located on http request and response to first cl…
geoje 004010c
refactor: extract to improve readability
geoje ebb02c0
refactor: change variable name to camelcase
geoje e5d5d3c
feat: login with post method
geoje adbb49f
refactor: fix typo exist to exists
geoje b57fad1
refactor: rename method to readable
geoje b745832
refactor: remove unused method on http request
geoje fdc5194
feat: set default protocol version to http1.1
geoje 8fe93a4
test: write for controller
geoje 65fdab9
test: view main page
geoje f9de082
fix: remove space on delimiter of semicolon on response
geoje c19b564
test: use containsSequence correctly
geoje a9d8a29
test: reflect for using POST method on login
geoje 100bcaa
test: find and get session
geoje 23963bb
test: response 400 for invalid http request
geoje 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 hidden or 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
18 changes: 0 additions & 18 deletions
18
study/src/main/java/cache/com/example/cachecontrol/CacheHandlerInterceptor.java
This file was deleted.
Oops, something went wrong.
26 changes: 13 additions & 13 deletions
26
study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java
This file contains hidden or 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,28 +1,28 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import com.google.common.net.HttpHeaders; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; | ||
|
||
import java.time.Duration; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
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) { | ||
registry.addInterceptor(new CacheHandlerInterceptor()).addPathPatterns("/"); | ||
registry.addInterceptor(new HandlerInterceptor() { | ||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { | ||
CacheControl cacheControl = CacheControl.maxAge(Duration.ofDays(365)).cachePublic(); | ||
response.addHeader(HttpHeaders.CACHE_CONTROL, cacheControl.getHeaderValue()); | ||
return true; | ||
} | ||
}).addPathPatterns("/resources/**"); | ||
WebContentInterceptor cacheInterceptor = new WebContentInterceptor(); | ||
cacheInterceptor.setCacheControl(CacheControl.noCache().cachePrivate()); | ||
registry.addInterceptor(cacheInterceptor) | ||
.addPathPatterns("/"); | ||
|
||
WebContentInterceptor resourceInterceptor = new WebContentInterceptor(); | ||
CacheControl cacheControl = CacheControl.maxAge(Duration.ofDays(365)).cachePublic(); | ||
resourceInterceptor.setCacheControl(cacheControl); | ||
registry.addInterceptor(resourceInterceptor) | ||
.addPathPatterns(PREFIX_STATIC_RESOURCES + "/**"); | ||
} | ||
} |
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
study/src/main/java/cache/com/example/version/HandlebarsConfig.java
This file contains hidden or 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,26 @@ | ||
package cache.com.example.version; | ||
|
||
import com.github.jknack.handlebars.springmvc.HandlebarsViewResolver; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.ViewResolver; | ||
|
||
@Configuration | ||
public class HandlebarsConfig { | ||
|
||
private final VersionHandlebarsHelper versionHandlebarsHelper; | ||
|
||
public HandlebarsConfig(VersionHandlebarsHelper versionHandlebarsHelper) { | ||
this.versionHandlebarsHelper = versionHandlebarsHelper; | ||
} | ||
|
||
@Bean | ||
public ViewResolver handlebarsViewResolver() { | ||
HandlebarsViewResolver viewResolver = new HandlebarsViewResolver(); | ||
viewResolver.registerHelper("staticUrls", versionHandlebarsHelper); | ||
viewResolver.setPrefix("classpath:/templates/"); | ||
viewResolver.setSuffix(".html"); | ||
|
||
return viewResolver; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,6 +1,3 @@ | ||
handlebars: | ||
suffix: .html | ||
|
||
server: | ||
tomcat: | ||
accept-count: 1 | ||
|
9 changes: 5 additions & 4 deletions
9
tomcat/src/main/java/com/techcourse/controller/AbstractController.java
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
tomcat/src/main/java/com/techcourse/controller/Controller.java
This file contains hidden or 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
10 changes: 7 additions & 3 deletions
10
tomcat/src/main/java/com/techcourse/controller/HomeController.java
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
10~15 라인에 해당하는 내용입니다.
Method Enum 클래스를 만드셨으니, 이를 활용해 볼 수 있겠군요 ~ 😸
아래 코드는 예시입니다.
request.method()를 직접 꺼내지 않고, request 안에 Method가 일치하는지 묻는 메서드(ex.
request.matchesMethod(Method.GET)
)를 만들 수도 있을 것 같아요~새양이 원하는 방식으로 바꿔보시죠 !
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.
네! 해당 부분을 수정하였습니다.
코멘트에 버그가난다는 것을 보고 후다닥 달려와 수정했을 때 이 부분이 문제더라구요!
Enum
과String
을 비교하려해서 항상false
가 된다는 경고 문구를 제거 무시해버린 사태였습니다 ㅠㅠ수정하여 더욱 좋게 바꾸었습니다~
isMethod
메서드!