Skip to content

[톰캣 구현하기 - 1,2단계] 베로(김은솔) 미션 제출합니다. #325

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 29 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
839ce23
test: 학습 테스트 완료
Cyma-s Sep 2, 2023
cc4330d
feat: index.html 응답하도록 수정
Cyma-s Sep 2, 2023
d9fbe85
feat: CSS, js 파일을 지원하도록 수정
Cyma-s Sep 2, 2023
f9ed141
feat: 로그인 시 user 정보 logging 기능 추가
Cyma-s Sep 2, 2023
b464eb2
feat: 로그인 결과에 따라 적절한 페이지로 리다이렉트 하도록 추가
Cyma-s Sep 3, 2023
3abf0bd
feat: 회원가입 기능 추가
Cyma-s Sep 3, 2023
2da4b10
feat: 쿠키에 JSESSIONID 값 저장하는 기능 추가
Cyma-s Sep 3, 2023
a72d6c4
feat: 유효한 Session이 존재하면 index.html 로 리다이렉트하는 기능 추가
Cyma-s Sep 4, 2023
6ed967f
test: 통합 테스트 추가
Cyma-s Sep 4, 2023
823621a
fix: 헤더 알파벳 순 정렬 추가
Cyma-s Sep 4, 2023
5ee4610
refactor: optional 값 변수로 추출
Cyma-s Sep 4, 2023
da74a18
refactor: stream 에 try-with-resources 적용
Cyma-s Sep 4, 2023
07b61d8
fix: 로깅 삭제
Cyma-s Sep 4, 2023
fa0d6f9
refactor: 생성자 접근 제어자 변경
Cyma-s Sep 4, 2023
5189da0
refactor: 불필요한 출력문 삭제
Cyma-s Sep 4, 2023
1b152ef
refactor: 쿠키 파싱 로직 리팩터링
Cyma-s Sep 4, 2023
5c588a0
refactor: static 클래스 private 생성자 추가
Cyma-s Sep 4, 2023
22379dc
refactor: EnumMap 으로 변경
Cyma-s Sep 4, 2023
9ecd360
refactor: 변수 이름 변경
Cyma-s Sep 4, 2023
48141c7
refactor: assertAll 로 감싸도록 변경
Cyma-s Sep 4, 2023
b354bfa
refactor: HttpMethod가 같은지 확인하는 메서드 추가
Cyma-s Sep 5, 2023
509870e
refactor: 사용하지 않는 생성자 삭제
Cyma-s Sep 5, 2023
74b22bf
refactor: 생성자 접근 제어자를 private 으로 변경
Cyma-s Sep 5, 2023
36ab2de
refactor: 세션 검증 메서드 추가
Cyma-s Sep 5, 2023
8971b54
refactor: HttpRequest 생성 책임 분리
Cyma-s Sep 5, 2023
67e89de
refactor: 빈 favicon 파일 추가
Cyma-s Sep 5, 2023
2e58ab4
refactor: 메서드 이름 변경
Cyma-s Sep 5, 2023
ca77c9e
refactor: 어색하지 않은 변수 이름으로 변경
Cyma-s Sep 5, 2023
5323db0
refactor: 메서드 이름 오타 수정
Cyma-s Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions study/src/test/java/cache/com/example/GreetingControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cache.com.example;

import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES;

import cache.com.example.version.ResourceVersion;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -10,10 +13,6 @@
import org.springframework.http.HttpHeaders;
import org.springframework.test.web.reactive.server.WebTestClient;

import java.time.Duration;

import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class GreetingControllerTest {

Expand All @@ -28,75 +27,77 @@ class GreetingControllerTest {
@Test
void testNoCachePrivate() {
final var response = webTestClient
.get()
.uri("/")
.exchange()
.expectStatus().isOk()
.expectHeader().cacheControl(CacheControl.noCache().cachePrivate())
.expectBody(String.class).returnResult();
.get()
.uri("/")
.exchange()
.expectStatus().isOk()
.expectHeader().cacheControl(CacheControl.noCache().cachePrivate())
.expectBody(String.class).returnResult();

log.info("response body\n{}", response.getResponseBody());
}

@Test
void testCompression() {
final var response = webTestClient
.get()
.uri("/")
.exchange()
.expectStatus().isOk()
.get()
.uri("/")
.exchange()
.expectStatus().isOk()

// gzip으로 요청 보내도 어떤 방식으로 압축할지 서버에서 결정한다.
// 웹브라우저에서 localhost:8080으로 접근하면 응답 헤더에 "Content-Encoding: gzip"이 있다.
.expectHeader().valueEquals(HttpHeaders.TRANSFER_ENCODING, "chunked")
.expectBody(String.class).returnResult();
// gzip으로 요청 보내도 어떤 방식으로 압축할지 서버에서 결정한다.
// 웹브라우저에서 localhost:8080으로 접근하면 응답 헤더에 "Content-Encoding: gzip"이 있다.
.expectHeader().valueEquals(HttpHeaders.TRANSFER_ENCODING, "chunked")
.expectBody(String.class).returnResult();

log.info("response body\n{}", response.getResponseBody());
}

@Test
void testETag() {
final var response = webTestClient
.get()
.uri("/etag")
.exchange()
.expectStatus().isOk()
.expectHeader().exists(HttpHeaders.ETAG)
.expectBody(String.class).returnResult();

.get()
.uri("/etag")
.exchange()
.expectStatus().isOk()
.expectHeader().exists(HttpHeaders.ETAG)
.expectBody(String.class).returnResult();
log.info("response header\n{}", response.getResponseHeaders());
log.info("response body\n{}", response.getResponseBody());
}

/**
* http://localhost:8080/resource-versioning
* 위 url의 html 파일에서 사용하는 js, css와 같은 정적 파일에 캐싱을 적용한다.
* 보통 정적 파일을 캐싱 무효화하기 위해 캐싱과 함께 버전을 적용시킨다.
* 위 url의 html 파일에서 사용하는 js, css와 같은 정적 파일에 캐싱을 적용한다. 보통 정적 파일을 캐싱 무효화하기 위해 캐싱과 함께 버전을 적용시킨다.
* 정적 파일에 변경 사항이 생기면 배포할 때 버전을 바꿔주면 적용된 캐싱을 무효화(Caching Busting)할 수 있다.
*/
@Test
void testCacheBustingOfStaticResources() {
final var uri = String.format("%s/%s/js/index.js", PREFIX_STATIC_RESOURCES, version.getVersion());

System.out.println(uri);

// "/resource-versioning/js/index.js" 경로의 정적 파일에 ETag를 사용한 캐싱이 적용되었는지 확인한다.
final var response = webTestClient
.get()
.uri(uri)
.exchange()
.expectStatus().isOk()
.expectHeader().exists(HttpHeaders.ETAG)
.expectHeader().cacheControl(CacheControl.maxAge(Duration.ofDays(365)).cachePublic())
.expectBody(String.class).returnResult();

.get()
.uri(uri)
.exchange()
.expectStatus().isOk()
.expectHeader().exists(HttpHeaders.ETAG)
.expectHeader().cacheControl(CacheControl.maxAge(Duration.ofDays(365)).cachePublic())
.expectBody(String.class).returnResult();

log.info("response header\n{}", response.getResponseHeaders());
log.info("response body\n{}", response.getResponseBody());

final var etag = response.getResponseHeaders().getETag();

// 캐싱되었다면 "/resource-versioning/js/index.js"로 다시 호출했을때 HTTP status는 304를 반환한다.
webTestClient.get()
.uri(uri)
.header(HttpHeaders.IF_NONE_MATCH, etag)
.exchange()
.expectStatus()
.isNotModified();
.uri(uri)
.header(HttpHeaders.IF_NONE_MATCH, etag)
.exchange()
.expectStatus()
.isNotModified();
}
}
17 changes: 9 additions & 8 deletions study/src/test/java/study/FileTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package study;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import org.springframework.util.ResourceUtils;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -24,11 +28,10 @@ class FileTest {
* resource 디렉터리의 경로는 어떻게 알아낼 수 있을까?
*/
@Test
void resource_디렉터리에_있는_파일의_경로를_찾는다() {
void resource_디렉터리에_있는_파일의_경로를_찾는다() throws IOException {
final String fileName = "nextstep.txt";

// todo
final String actual = "";
final String actual = ResourceUtils.getURL("classpath:" + fileName).getPath();

assertThat(actual).endsWith(fileName);
}
Expand All @@ -40,14 +43,12 @@ class FileTest {
* File, Files 클래스를 사용하여 파일의 내용을 읽어보자.
*/
@Test
void 파일의_내용을_읽는다() {
void 파일의_내용을_읽는다() throws IOException {
final String fileName = "nextstep.txt";

// todo
final Path path = null;
final Path path = ResourceUtils.getFile("classpath:" + fileName).toPath();

// todo
final List<String> actual = Collections.emptyList();
final List<String> actual = Files.readAllLines(path);

assertThat(actual).containsOnly("nextstep");
}
Expand Down
Loading