Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fed02f6
fix: remove implementation logback-classic on gradle (#501)
geoje Sep 5, 2024
7e91356
fix: add threads min-spare configuration on properties (#502)
geoje Sep 5, 2024
4a259b5
test: FileTest 및 IOStreamTest 통과
seunghye218 Sep 4, 2024
fddfdc6
chore: lombok 의존성 추가
seunghye218 Sep 5, 2024
1d08960
feat: 1-1 'GET /index.html 응답하기' 기능 구현
seunghye218 Sep 5, 2024
90931d9
feat: 1-2 CSS 지원하기 기능 구현
seunghye218 Sep 5, 2024
7319283
refactor: getResponse 로직 메서드 분리
seunghye218 Sep 5, 2024
ba5010d
refactor: 간단한 예외처리 추가
seunghye218 Sep 5, 2024
c037870
refactor(HttpRequest): path와 parameters 추가 및 파싱
seunghye218 Sep 5, 2024
7d4f988
feat: 1-3 Query String 파싱 구현
seunghye218 Sep 5, 2024
38a85a1
feat: 2-1 로그인 여부에 따라 페이지 이동 구현
seunghye218 Sep 5, 2024
721b7e9
refactor: HttpResponse 객체 추가
seunghye218 Sep 6, 2024
6f53481
refactor: 메서드 인자 및 이름 변경
seunghye218 Sep 6, 2024
db007a2
fix: 템플릿 엔진 미사용
seunghye218 Sep 6, 2024
36c22be
test: 휴리스틱 캐싱 제거
seunghye218 Sep 6, 2024
add93cd
test: HTTP Compression 설정
seunghye218 Sep 6, 2024
7f37783
fix: 알맞은 resource 이름 반환
seunghye218 Sep 6, 2024
7497b66
test: ETag/If-None-Match 적용
seunghye218 Sep 6, 2024
a633a27
test: 캐시 무효화
seunghye218 Sep 6, 2024
34d44a6
feat: POST 방식으로 회원가입
seunghye218 Sep 6, 2024
837933e
fix: 파라미터 없는 /login 접속 불가능 수정
seunghye218 Sep 6, 2024
1b6cb98
fix: 요청 본문 URLDecode
seunghye218 Sep 6, 2024
0125570
fix: Cookie에 JSESSIONID 값 저장
seunghye218 Sep 6, 2024
4109760
feat: Session 구현
seunghye218 Sep 6, 2024
b3de68a
refactor: 요청 URL 디코딩
seunghye218 Sep 9, 2024
ac157e2
refactor: application/x-www-form-urlencoded MIME 타입 요청 본문 값을 파라미터로 처리
seunghye218 Sep 9, 2024
c3c3791
refactor(HttpResponse): 생성자 추가
seunghye218 Sep 9, 2024
1ceb56d
refactor(HttpResponse): 상태 코드 및 메시지 열거형 분리
seunghye218 Sep 9, 2024
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
1 change: 0 additions & 1 deletion study/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'ch.qos.logback:logback-classic:1.5.7'
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
implementation 'pl.allegro.tech.boot:handlebars-spring-boot-starter:0.4.1'
Expand Down
8 changes: 4 additions & 4 deletions study/src/main/java/cache/com/example/GreetingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GreetingController {

@GetMapping("/")
public String index() {
return "index";
return "index.html";
}

/**
Expand All @@ -25,16 +25,16 @@ public String cacheControl(final HttpServletResponse response) {
.cachePrivate()
.getHeaderValue();
response.addHeader(HttpHeaders.CACHE_CONTROL, cacheControl);
return "index";
return "index.html";
}

@GetMapping("/etag")
public String etag() {
return "index";
return "index.html";
}

@GetMapping("/resource-versioning")
public String resourceVersioning() {
return "resource-versioning";
return "resource-versioning.html";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cache.com.example.cachecontrol;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class CacheControlInterceptor implements HandlerInterceptor {

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
final String cacheControl = CacheControl
.noCache()
.cachePrivate()
.getHeaderValue();
response.addHeader(HttpHeaders.CACHE_CONTROL, cacheControl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public class CacheWebConfig implements WebMvcConfigurer {

@Override
public void addInterceptors(final InterceptorRegistry registry) {
CacheControlInterceptor interceptor = new CacheControlInterceptor();
registry.addInterceptor(interceptor);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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() {
final var filter = new ShallowEtagHeaderFilter();
final var registrationBean = new FilterRegistrationBean<>(filter);
registrationBean.addUrlPatterns("/etag");
return registrationBean;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cache.com.example.version;

import java.time.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand All @@ -20,6 +22,8 @@ public CacheBustingWebConfig(ResourceVersion version) {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler(PREFIX_STATIC_RESOURCES + "/" + version.getVersion() + "/**")
.addResourceLocations("classpath:/static/");
.addResourceLocations("classpath:/static/")
.setEtagGenerator(request -> version.getVersion())
.setCacheControl(CacheControl.maxAge(Duration.ofDays(365)).cachePublic());
}
}
4 changes: 4 additions & 0 deletions study/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ server:
accept-count: 1
max-connections: 1
threads:
min-spare: 2
max: 2
compression:
enabled: true
min-response-size: 10
36 changes: 18 additions & 18 deletions study/src/test/java/study/FileTest.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
package study;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;

/**
* 웹서버는 사용자가 요청한 html 파일을 제공 할 수 있어야 한다.
* File 클래스를 사용해서 파일을 읽어오고, 사용자에게 전달한다.
* 웹서버는 사용자가 요청한 html 파일을 제공 할 수 있어야 한다. File 클래스를 사용해서 파일을 읽어오고, 사용자에게 전달한다.
*/
@DisplayName("File 클래스 학습 테스트")
class FileTest {

/**
* resource 디렉터리 경로 찾기
*
* File 객체를 생성하려면 파일의 경로를 알아야 한다.
* 자바 애플리케이션은 resource 디렉터리에 HTML, CSS 같은 정적 파일을 저장한다.
* resource 디렉터리의 경로는 어떻게 알아낼 수 있을까?
* <p>
* File 객체를 생성하려면 파일의 경로를 알아야 한다. 자바 애플리케이션은 resource 디렉터리에 HTML, CSS 같은 정적 파일을 저장한다. resource 디렉터리의 경로는 어떻게 알아낼 수
* 있을까?
*/
@Test
void resource_디렉터리에_있는_파일의_경로를_찾는다() {
final String fileName = "nextstep.txt";

// todo
final String actual = "";
ClassPathResource resource = new ClassPathResource(fileName);
final String actual = resource.getFilename();

assertThat(actual).endsWith(fileName);
}

/**
* 파일 내용 읽기
*
* 읽어온 파일의 내용을 I/O Stream을 사용해서 사용자에게 전달 해야 한다.
* File, Files 클래스를 사용하여 파일의 내용을 읽어보자.
* <p>
* 읽어온 파일의 내용을 I/O Stream을 사용해서 사용자에게 전달 해야 한다. File, Files 클래스를 사용하여 파일의 내용을 읽어보자.
*/
@Test
void 파일의_내용을_읽는다() {
void 파일의_내용을_읽는다() throws IOException {
final String fileName = "nextstep.txt";

// todo
final Path path = null;
ClassPathResource resource = new ClassPathResource(fileName);
final Path path = resource.getFile().toPath();

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

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