-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[톰캣 구현하기 1, 2단계] 안나 (김민겸) 미션 제출합니다. (#571)
* test: 학습 테스트 진행 * feat: `/index.html`에 접근했을 때 static/index.html 파일이 보여지도록 구현 * feat: 자원에 따라 다른 Conent-Type으로 응답을 보내도록 수정 * fix: remove implementation logback-classic on gradle (#501) * fix: 공백 처리 때문에 index.html이 불러와지지 않는 현상 해결 * feat: 로그인 요청 시 쿼리 파라미터를 파싱하는 기능 구현 * fix: add threads min-spare configuration on properties (#502) * feat: 로그인에 성공하거나 실패한 경우 다른 페이지로 리다이렉트하는 * feat: POST 요청으로 회원 가입 시 요청 본문에서 정보를 가져와 사용자 저장하는 기능 구현 * feat: 로그인 시 POST 요청을 보내도록 수정 * feat: 로그인 시 세션 아이디를 쿠키에 등록하는 기능 구현 * feat: 쿠키에 JSESSIONID가 없을 때 Set-Cookie를 발급하는 기능 구현 * feat: 이미 로그인한 회원의 경우 로그인 페이지에 접근 불가하도록 구현 * refactor: 쿠키가 없을 때 일반 페이지에 접근하면 세션 아이디를 주지 않음 * feat: HTTP 활용 학습 테스트 진행 * refactor: 뭉친 코드를 클래스 분리하여 리팩토링 * fix: JSESSIONID를 추가하지 않아 로그인되지 않는 문제 해결 * fix: 세션 아이디가 달라서 로그인 시 로그인 페이지가 접속되는 현상 해결 * refactor: 기존 코드 주석 제거 * style: 주석 제거 및 컨벤션 맞추기 * refactor: 미구현된 파일 제거 * refactor: 필터를 사용하여 ETag를 지정하는 것으로 변경 * refactor: 인터셉터에서 CacheControl을 적용할 수 있도록 수정 * refactor: Content-Length 헤더 이름을 상수화 * refactor: 정적 파일을 한 번에 처리하도록 리팩토링 * fix: Json 파일을 보내는 경우를 고려하여 MediaType 수정 * refactor: 로그인 시 쿠키 세션을 꺼내오는 코드 가독성 개선 * refactor: 요청한 사용자 정보가 없는 경우 401 페이지를 보여주도록 수정 * refactor: 쿠키의 키값을 상수화하여 리팩토링 --------- Co-authored-by: Gyeongho Yang <[email protected]>
- Loading branch information
1 parent
0b698a2
commit 37b1313
Showing
17 changed files
with
427 additions
and
34 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
15 changes: 15 additions & 0 deletions
15
study/src/main/java/cache/com/example/cachecontrol/CacheControlInterceptor.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,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; | ||
} | ||
} |
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
15 changes: 10 additions & 5 deletions
15
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,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; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -6,4 +6,7 @@ server: | |
accept-count: 1 | ||
max-connections: 1 | ||
threads: | ||
min-spare: 2 | ||
max: 2 | ||
compression: | ||
enabled: true |
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
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
57 changes: 57 additions & 0 deletions
57
tomcat/src/main/java/org/apache/coyote/http11/request/HttpRequest.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,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()); | ||
} | ||
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; | ||
} | ||
|
||
public String getMethod() { | ||
return method; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public String getCookie() { | ||
return headers.get("Cookie"); | ||
} | ||
|
||
public String getBody() { | ||
return body; | ||
} | ||
} |
Oops, something went wrong.