-
Notifications
You must be signed in to change notification settings - Fork 388
[톰캣 구현하기 1, 2단계] 안나 (김민겸) 미션 제출합니다. #571
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
Changes from all commits
0e80615
fe4981a
9703596
fed02f6
bffee2a
0964ae2
7e91356
72958ed
a535e6d
3d9dc32
88c4a05
b0da4a6
795a568
9692263
38c53ab
66597e3
acde025
df161b1
5dc81b2
da09610
85007fd
f1aed30
6211629
de9a2ef
95abccd
605727c
539be1c
407826a
2439262
0bb26a7
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,15 @@ | ||
| package cache.com.example.cachecontrol; | ||
|
|
||
| import org.springframework.web.servlet.HandlerInterceptor; | ||
|
|
||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
|
|
||
| public class CacheControlInterceptor implements HandlerInterceptor { | ||
|
|
||
| @Override | ||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { | ||
| response.addHeader("Cache-Control", "no-cache, private"); | ||
| return true; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| 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()); | ||
| filterRegistrationBean.addUrlPatterns("/etag"); | ||
| return filterRegistrationBean; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,7 @@ server: | |
| accept-count: 1 | ||
| max-connections: 1 | ||
| threads: | ||
| min-spare: 2 | ||
| max: 2 | ||
| compression: | ||
| enabled: true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package org.apache.coyote.http11.request; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class HttpRequest { | ||
|
|
||
| private static final String CONTENT_LENGTH = "Content-Length"; | ||
|
|
||
| private final String method; | ||
| private final String path; | ||
| private final Map<String, String> headers = new HashMap<>(); | ||
| private final String body; | ||
|
|
||
| public HttpRequest(BufferedReader reader) throws IOException { | ||
| String initialLine = reader.readLine(); | ||
| this.method = initialLine.split(" ")[0]; | ||
| this.path = initialLine.split(" ")[1]; | ||
| String line; | ||
| while ((line = reader.readLine()) != null && !line.isEmpty()) { | ||
| String[] header = line.split(":"); | ||
| headers.put(header[0].trim(), header[1].trim()); | ||
jinchiim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| this.body = parseBody(reader); | ||
| } | ||
|
|
||
| private String parseBody(BufferedReader reader) throws IOException { | ||
| if(headers.get(CONTENT_LENGTH) == null) { | ||
| return null; | ||
| } | ||
| int contentLength = Integer.parseInt(headers.get(CONTENT_LENGTH)); | ||
| if(contentLength > 0) { | ||
| char[] body = new char[contentLength]; | ||
| reader.read(body, 0, contentLength); | ||
| return new String(body); | ||
| } | ||
| return null; | ||
|
Comment on lines
+38
to
+39
Member
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. 이것은 궁금한 부분인데요!
Author
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. Content Length가 0이라면 본문이 없는 요청이에요 ! GET 메서드로 보내는 상황 등이 이에 해당할거에요.
Member
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. 헤더는 조작될 수도 있지 않을까요?? 저도 몰랐는데 이를 찾아보니, 이 사실을 알고 저도 예외처리를 빡세게 해보려고 하는데 같이 시작하는 것은 어떨까요? 😋 |
||
| } | ||
|
|
||
| public String getMethod() { | ||
| return method; | ||
| } | ||
|
|
||
| public String getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| public String getCookie() { | ||
| return headers.get("Cookie"); | ||
| } | ||
|
|
||
| public String getBody() { | ||
| return body; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.