diff --git a/study/build.gradle b/study/build.gradle index 5c69542f84..87a1f0313c 100644 --- a/study/build.gradle +++ b/study/build.gradle @@ -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' diff --git a/study/src/main/java/cache/com/example/GreetingController.java b/study/src/main/java/cache/com/example/GreetingController.java index c0053cda42..e95565ba1c 100644 --- a/study/src/main/java/cache/com/example/GreetingController.java +++ b/study/src/main/java/cache/com/example/GreetingController.java @@ -1,18 +1,17 @@ package cache.com.example; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.CacheControl; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import jakarta.servlet.http.HttpServletResponse; - @Controller public class GreetingController { @GetMapping("/") public String index() { - return "index"; + return "index.html"; } /** @@ -30,7 +29,8 @@ public String cacheControl(final HttpServletResponse response) { @GetMapping("/etag") public String etag() { - return "index"; + + return "index.html"; } @GetMapping("/resource-versioning") diff --git a/study/src/main/java/cache/com/example/cachecontrol/CacheControlInterceptor.java b/study/src/main/java/cache/com/example/cachecontrol/CacheControlInterceptor.java new file mode 100644 index 0000000000..02a02a12ae --- /dev/null +++ b/study/src/main/java/cache/com/example/cachecontrol/CacheControlInterceptor.java @@ -0,0 +1,24 @@ +package cache.com.example.cachecontrol; + +import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +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 { + if (!request.getRequestURI().startsWith(PREFIX_STATIC_RESOURCES)) { + response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, private"); + } + } +} diff --git a/study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java b/study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java index 305b1f1e1e..1c8197d1e2 100644 --- a/study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java +++ b/study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java @@ -9,5 +9,6 @@ public class CacheWebConfig implements WebMvcConfigurer { @Override public void addInterceptors(final InterceptorRegistry registry) { + registry.addInterceptor(new CacheControlInterceptor()); } } diff --git a/study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java b/study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java index 41ef7a3d9a..9bcea82659 100644 --- a/study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java +++ b/study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java @@ -1,12 +1,21 @@ package cache.com.example.etag; +import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; + +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() { -// return null; -// } + @Bean + public FilterRegistrationBean shallowEtagHeaderFilter() { + FilterRegistrationBean filterRegistrationBean + = new FilterRegistrationBean<>(new ShallowEtagHeaderFilter()); + filterRegistrationBean.addUrlPatterns("/etag"); + filterRegistrationBean.addUrlPatterns(PREFIX_STATIC_RESOURCES + "/*"); + return filterRegistrationBean; + } } diff --git a/study/src/main/java/cache/com/example/version/CacheBustingWebConfig.java b/study/src/main/java/cache/com/example/version/CacheBustingWebConfig.java index 6da6d2c795..c7addcdab4 100644 --- a/study/src/main/java/cache/com/example/version/CacheBustingWebConfig.java +++ b/study/src/main/java/cache/com/example/version/CacheBustingWebConfig.java @@ -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; @@ -20,6 +22,7 @@ public CacheBustingWebConfig(ResourceVersion version) { @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { registry.addResourceHandler(PREFIX_STATIC_RESOURCES + "/" + version.getVersion() + "/**") - .addResourceLocations("classpath:/static/"); + .addResourceLocations("classpath:/static/") + .setCacheControl(CacheControl.maxAge(Duration.ofDays(365)).cachePublic()); } } diff --git a/study/src/main/resources/application.yml b/study/src/main/resources/application.yml index 4e8655a962..8b74bdfd88 100644 --- a/study/src/main/resources/application.yml +++ b/study/src/main/resources/application.yml @@ -6,4 +6,8 @@ server: accept-count: 1 max-connections: 1 threads: + min-spare: 2 max: 2 + compression: + enabled: true + min-response-size: 10 diff --git a/study/src/main/resources/templates/index.html b/study/src/main/resources/static/index.html similarity index 100% rename from study/src/main/resources/templates/index.html rename to study/src/main/resources/static/index.html diff --git a/study/src/main/resources/templates/resource-versioning.html b/study/src/main/resources/static/resource-versioning.html similarity index 100% rename from study/src/main/resources/templates/resource-versioning.html rename to study/src/main/resources/static/resource-versioning.html diff --git a/study/src/test/java/study/FileTest.java b/study/src/test/java/study/FileTest.java index e1b6cca042..7f2c05f7c1 100644 --- a/study/src/test/java/study/FileTest.java +++ b/study/src/test/java/study/FileTest.java @@ -1,54 +1,59 @@ 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.BufferedReader; +import java.net.URISyntaxException; +import java.net.URL; +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 java.util.Objects; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; /** - * 웹서버는 사용자가 요청한 html 파일을 제공 할 수 있어야 한다. - * File 클래스를 사용해서 파일을 읽어오고, 사용자에게 전달한다. + * 웹서버는 사용자가 요청한 html 파일을 제공 할 수 있어야 한다. File 클래스를 사용해서 파일을 읽어오고, 사용자에게 전달한다. */ @DisplayName("File 클래스 학습 테스트") class FileTest { /** * resource 디렉터리 경로 찾기 - * - * File 객체를 생성하려면 파일의 경로를 알아야 한다. - * 자바 애플리케이션은 resource 디렉터리에 HTML, CSS 같은 정적 파일을 저장한다. - * resource 디렉터리의 경로는 어떻게 알아낼 수 있을까? + *

+ * File 객체를 생성하려면 파일의 경로를 알아야 한다. 자바 애플리케이션은 resource 디렉터리에 HTML, CSS 같은 정적 파일을 저장한다. resource 디렉터리의 경로는 어떻게 알아낼 수 + * 있을까? */ @Test void resource_디렉터리에_있는_파일의_경로를_찾는다() { final String fileName = "nextstep.txt"; - // todo - final String actual = ""; + URL resource = getClass().getClassLoader().getResource(fileName); + final String actual = Objects.requireNonNull(resource).getFile(); assertThat(actual).endsWith(fileName); } /** * 파일 내용 읽기 - * - * 읽어온 파일의 내용을 I/O Stream을 사용해서 사용자에게 전달 해야 한다. - * File, Files 클래스를 사용하여 파일의 내용을 읽어보자. + *

+ * 읽어온 파일의 내용을 I/O Stream을 사용해서 사용자에게 전달 해야 한다. File, Files 클래스를 사용하여 파일의 내용을 읽어보자. */ @Test - void 파일의_내용을_읽는다() { + void 파일의_내용을_읽는다() throws URISyntaxException { final String fileName = "nextstep.txt"; - // todo - final Path path = null; + URL resource = getClass().getClassLoader().getResource(fileName); + Path path = Path.of(resource.toURI()); + + try (BufferedReader bufferedReader = Files.newBufferedReader(path)) { + List actual = bufferedReader.lines().toList(); + assertThat(actual).containsOnly("nextstep"); + } catch (Exception e) { + } - // todo - final List actual = Collections.emptyList(); +// final List actual = Files.readLines(file, Charset.defaultCharset()); <- 나중에 해결 안 됨 - assertThat(actual).containsOnly("nextstep"); +// assertThat(actual).containsOnly("nextstep"); } } diff --git a/study/src/test/java/study/IOStreamTest.java b/study/src/test/java/study/IOStreamTest.java index 47a79356b6..442c308240 100644 --- a/study/src/test/java/study/IOStreamTest.java +++ b/study/src/test/java/study/IOStreamTest.java @@ -1,45 +1,50 @@ package study; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import java.io.*; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - /** - * 자바는 스트림(Stream)으로부터 I/O를 사용한다. - * 입출력(I/O)은 하나의 시스템에서 다른 시스템으로 데이터를 이동 시킬 때 사용한다. - * - * InputStream은 데이터를 읽고, OutputStream은 데이터를 쓴다. - * FilterStream은 InputStream이나 OutputStream에 연결될 수 있다. - * FilterStream은 읽거나 쓰는 데이터를 수정할 때 사용한다. (e.g. 암호화, 압축, 포맷 변환) - * - * Stream은 데이터를 바이트로 읽고 쓴다. - * 바이트가 아닌 텍스트(문자)를 읽고 쓰려면 Reader와 Writer 클래스를 연결한다. - * Reader, Writer는 다양한 문자 인코딩(e.g. UTF-8)을 처리할 수 있다. + * 자바는 스트림(Stream)으로부터 I/O를 사용한다. 입출력(I/O)은 하나의 시스템에서 다른 시스템으로 데이터를 이동 시킬 때 사용한다. + *

+ * InputStream은 데이터를 읽고, OutputStream은 데이터를 쓴다. FilterStream은 InputStream이나 OutputStream에 연결될 수 있다. FilterStream은 읽거나 쓰는 + * 데이터를 수정할 때 사용한다. (e.g. 암호화, 압축, 포맷 변환) + *

+ * Stream은 데이터를 바이트로 읽고 쓴다. 바이트가 아닌 텍스트(문자)를 읽고 쓰려면 Reader와 Writer 클래스를 연결한다. Reader, Writer는 다양한 문자 인코딩(e.g. UTF-8)을 + * 처리할 수 있다. */ @DisplayName("Java I/O Stream 클래스 학습 테스트") class IOStreamTest { /** * OutputStream 학습하기 - * - * 자바의 기본 출력 클래스는 java.io.OutputStream이다. - * OutputStream의 write(int b) 메서드는 기반 메서드이다. + *

+ * 자바의 기본 출력 클래스는 java.io.OutputStream이다. OutputStream의 write(int b) 메서드는 기반 메서드이다. * public abstract void write(int b) throws IOException; */ @Nested class OutputStream_학습_테스트 { /** - * OutputStream은 다른 매체에 바이트로 데이터를 쓸 때 사용한다. - * OutputStream의 서브 클래스(subclass)는 특정 매체에 데이터를 쓰기 위해 write(int b) 메서드를 사용한다. - * 예를 들어, FilterOutputStream은 파일로 데이터를 쓸 때, - * 또는 DataOutputStream은 자바의 primitive type data를 다른 매체로 데이터를 쓸 때 사용한다. - * + * OutputStream은 다른 매체에 바이트로 데이터를 쓸 때 사용한다. OutputStream의 서브 클래스(subclass)는 특정 매체에 데이터를 쓰기 위해 write(int b) 메서드를 + * 사용한다. 예를 들어, FilterOutputStream은 파일로 데이터를 쓸 때, 또는 DataOutputStream은 자바의 primitive type data를 다른 매체로 데이터를 쓸 때 + * 사용한다. + *

* write 메서드는 데이터를 바이트로 출력하기 때문에 비효율적이다. * write(byte[] data)write(byte b[], int off, int len) 메서드는 * 1바이트 이상을 한 번에 전송 할 수 있어 훨씬 효율적이다. @@ -54,6 +59,8 @@ class OutputStream_학습_테스트 { * OutputStream 객체의 write 메서드를 사용해서 테스트를 통과시킨다 */ + outputStream.write(bytes); + final String actual = outputStream.toString(); assertThat(actual).isEqualTo("nextstep"); @@ -61,13 +68,10 @@ class OutputStream_학습_테스트 { } /** - * 효율적인 전송을 위해 스트림에서 버퍼링을 사용 할 수 있다. - * BufferedOutputStream 필터를 연결하면 버퍼링이 가능하다. - * - * 버퍼링을 사용하면 OutputStream을 사용할 때 flush를 사용하자. - * flush() 메서드는 버퍼가 아직 가득 차지 않은 상황에서 강제로 버퍼의 내용을 전송한다. - * Stream은 동기(synchronous)로 동작하기 때문에 버퍼가 찰 때까지 기다리면 - * 데드락(deadlock) 상태가 되기 때문에 flush로 해제해야 한다. + * 효율적인 전송을 위해 스트림에서 버퍼링을 사용 할 수 있다. BufferedOutputStream 필터를 연결하면 버퍼링이 가능하다. + *

+ * 버퍼링을 사용하면 OutputStream을 사용할 때 flush를 사용하자. flush() 메서드는 버퍼가 아직 가득 차지 않은 상황에서 강제로 버퍼의 내용을 전송한다. Stream은 + * 동기(synchronous)로 동작하기 때문에 버퍼가 찰 때까지 기다리면 데드락(deadlock) 상태가 되기 때문에 flush로 해제해야 한다. */ @Test void BufferedOutputStream을_사용하면_버퍼링이_가능하다() throws IOException { @@ -78,14 +82,14 @@ class OutputStream_학습_테스트 { * flush를 사용해서 테스트를 통과시킨다. * ByteArrayOutputStream과 어떤 차이가 있을까? */ + outputStream.flush(); verify(outputStream, atLeastOnce()).flush(); outputStream.close(); } /** - * 스트림 사용이 끝나면 항상 close() 메서드를 호출하여 스트림을 닫는다. - * 장시간 스트림을 닫지 않으면 파일, 포트 등 다양한 리소스에서 누수(leak)가 발생한다. + * 스트림 사용이 끝나면 항상 close() 메서드를 호출하여 스트림을 닫는다. 장시간 스트림을 닫지 않으면 파일, 포트 등 다양한 리소스에서 누수(leak)가 발생한다. */ @Test void OutputStream은_사용하고_나서_close_처리를_해준다() throws IOException { @@ -96,27 +100,26 @@ class OutputStream_학습_테스트 { * try-with-resources를 사용한다. * java 9 이상에서는 변수를 try-with-resources로 처리할 수 있다. */ - + try (outputStream) { + } verify(outputStream, atLeastOnce()).close(); } } /** * InputStream 학습하기 - * - * 자바의 기본 입력 클래스는 java.io.InputStream이다. - * InputStream은 다른 매체로부터 바이트로 데이터를 읽을 때 사용한다. - * InputStream의 read() 메서드는 기반 메서드이다. + *

+ * 자바의 기본 입력 클래스는 java.io.InputStream이다. InputStream은 다른 매체로부터 바이트로 데이터를 읽을 때 사용한다. InputStream의 read() 메서드는 기반 + * 메서드이다. * public abstract int read() throws IOException; - * + *

* InputStream의 서브 클래스(subclass)는 특정 매체에 데이터를 읽기 위해 read() 메서드를 사용한다. */ @Nested class InputStream_학습_테스트 { /** - * read() 메서드는 매체로부터 단일 바이트를 읽는데, 0부터 255 사이의 값을 int 타입으로 반환한다. - * int 값을 byte 타입으로 변환하면 -128부터 127 사이의 값으로 변환된다. + * read() 메서드는 매체로부터 단일 바이트를 읽는데, 0부터 255 사이의 값을 int 타입으로 반환한다. int 값을 byte 타입으로 변환하면 -128부터 127 사이의 값으로 변환된다. * 그리고 Stream 끝에 도달하면 -1을 반환한다. */ @Test @@ -128,7 +131,9 @@ class InputStream_학습_테스트 { * todo * inputStream에서 바이트로 반환한 값을 문자열로 어떻게 바꿀까? */ - final String actual = ""; + inputStream.readAllBytes(); + + final String actual = new String(bytes); assertThat(actual).isEqualTo("🤩"); assertThat(inputStream.read()).isEqualTo(-1); @@ -136,8 +141,7 @@ class InputStream_학습_테스트 { } /** - * 스트림 사용이 끝나면 항상 close() 메서드를 호출하여 스트림을 닫는다. - * 장시간 스트림을 닫지 않으면 파일, 포트 등 다양한 리소스에서 누수(leak)가 발생한다. + * 스트림 사용이 끝나면 항상 close() 메서드를 호출하여 스트림을 닫는다. 장시간 스트림을 닫지 않으면 파일, 포트 등 다양한 리소스에서 누수(leak)가 발생한다. */ @Test void InputStream은_사용하고_나서_close_처리를_해준다() throws IOException { @@ -148,6 +152,9 @@ class InputStream_학습_테스트 { * try-with-resources를 사용한다. * java 9 이상에서는 변수를 try-with-resources로 처리할 수 있다. */ + try (inputStream) { + + } verify(inputStream, atLeastOnce()).close(); } @@ -155,26 +162,24 @@ class InputStream_학습_테스트 { /** * FilterStream 학습하기 - * - * 필터는 필터 스트림, reader, writer로 나뉜다. - * 필터는 바이트를 다른 데이터 형식으로 변환 할 때 사용한다. - * reader, writer는 UTF-8, ISO 8859-1 같은 형식으로 인코딩된 텍스트를 처리하는 데 사용된다. + *

+ * 필터는 필터 스트림, reader, writer로 나뉜다. 필터는 바이트를 다른 데이터 형식으로 변환 할 때 사용한다. reader, writer는 UTF-8, ISO 8859-1 같은 형식으로 인코딩된 + * 텍스트를 처리하는 데 사용된다. */ @Nested class FilterStream_학습_테스트 { /** - * BufferedInputStream은 데이터 처리 속도를 높이기 위해 데이터를 버퍼에 저장한다. - * InputStream 객체를 생성하고 필터 생성자에 전달하면 필터에 연결된다. - * 버퍼 크기를 지정하지 않으면 버퍼의 기본 사이즈는 얼마일까? + * BufferedInputStream은 데이터 처리 속도를 높이기 위해 데이터를 버퍼에 저장한다. InputStream 객체를 생성하고 필터 생성자에 전달하면 필터에 연결된다. 버퍼 크기를 지정하지 + * 않으면 버퍼의 기본 사이즈는 얼마일까? */ @Test - void 필터인_BufferedInputStream를_사용해보자() { + void 필터인_BufferedInputStream를_사용해보자() throws IOException { final String text = "필터에 연결해보자."; final InputStream inputStream = new ByteArrayInputStream(text.getBytes()); - final InputStream bufferedInputStream = null; + final InputStream bufferedInputStream = new BufferedInputStream(inputStream); // buffer size = 8192 bytes - final byte[] actual = new byte[0]; + final byte[] actual = bufferedInputStream.readAllBytes(); assertThat(bufferedInputStream).isInstanceOf(FilterInputStream.class); assertThat(actual).isEqualTo("필터에 연결해보자.".getBytes()); @@ -182,30 +187,32 @@ class FilterStream_학습_테스트 { } /** - * 자바의 기본 문자열은 UTF-16 유니코드 인코딩을 사용한다. - * 문자열이 아닌 바이트 단위로 처리하려니 불편하다. - * 그리고 바이트를 문자(char)로 처리하려면 인코딩을 신경 써야 한다. - * reader, writer를 사용하면 입출력 스트림을 바이트가 아닌 문자 단위로 데이터를 처리하게 된다. - * 그리고 InputStreamReader를 사용하면 지정된 인코딩에 따라 유니코드 문자로 변환할 수 있다. + * 자바의 기본 문자열은 UTF-16 유니코드 인코딩을 사용한다. 문자열이 아닌 바이트 단위로 처리하려니 불편하다. 그리고 바이트를 문자(char)로 처리하려면 인코딩을 신경 써야 한다. reader, + * writer를 사용하면 입출력 스트림을 바이트가 아닌 문자 단위로 데이터를 처리하게 된다. 그리고 InputStreamReader를 사용하면 지정된 인코딩에 따라 유니코드 문자로 변환할 수 있다. */ @Nested class InputStreamReader_학습_테스트 { /** - * InputStreamReader를 사용해서 바이트를 문자(char)로 읽어온다. - * 읽어온 문자(char)를 문자열(String)로 처리하자. - * 필터인 BufferedReader를 사용하면 readLine 메서드를 사용해서 문자열(String)을 한 줄 씩 읽어올 수 있다. + * InputStreamReader를 사용해서 바이트를 문자(char)로 읽어온다. 읽어온 문자(char)를 문자열(String)로 처리하자. 필터인 BufferedReader를 사용하면 + * readLine 메서드를 사용해서 문자열(String)을 한 줄 씩 읽어올 수 있다. */ @Test - void BufferedReader를_사용하여_문자열을_읽어온다() { + void BufferedReader를_사용하여_문자열을_읽어온다() throws IOException { final String emoji = String.join("\r\n", "😀😃😄😁😆😅😂🤣🥲☺️😊", "😇🙂🙃😉😌😍🥰😘😗😙😚", "😋😛😝😜🤪🤨🧐🤓😎🥸🤩", ""); final InputStream inputStream = new ByteArrayInputStream(emoji.getBytes()); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + String line; final StringBuilder actual = new StringBuilder(); + while ((line = bufferedReader.readLine()) != null) { + actual.append(line); + actual.append("\r\n"); + } assertThat(actual).hasToString(emoji); } diff --git a/tomcat/README.md b/tomcat/README.md new file mode 100644 index 0000000000..3a371aea70 --- /dev/null +++ b/tomcat/README.md @@ -0,0 +1,22 @@ +## 1단계 - HTTP 서버 구현하기 + +- [x] GET /index.html 응답하기 +- [x] CSS 지원하기 +- [x] Query String 파싱 + +## 2단계 - 로그인 구현하기 + +- [x] HTTP Status Code 302 + - [x] 로그인 성공 시 http status code 302 반환 + - [x] 로그인 성공 시 `/index.html`로 리다이렉트, 실패 시 `/401.html`로 리다이렉트 +- [x] POST 방식으로 회원가입 + - [x] `/register` 접속하면 회원가입 페이지(register.html) 응답 + - [x] 회원가입 페이지를 보여줄 때는 GET 사용, 회원가입 버튼을 누르면 POST 사용 + - [x] 회원가입 완료 시 `/index.html`로 리다이렉트 + - [x] 로그인 페이지에서도 로그인 버튼을 누르면 POST 사용 +- [x] Cookie에 JSESSIONID 값 저장하기 + - [x] Cookie 클래스 추가 + - [x] HTTP Request Header의 Cookie에 JSESSIONID가 없으면 Set-Cookie 반환 +- [x] Session 구현하기 + - [x] 로그인 성공 시 Session 객체의 값으로 User 객체 저장 + - [x] 로그인된 상태에서 `/login` 접속하면 `index.html`로 리다이렉트 diff --git a/tomcat/src/main/java/org/apache/catalina/Manager.java b/tomcat/src/main/java/org/apache/catalina/Manager.java index e69410f6a9..2fef449bfb 100644 --- a/tomcat/src/main/java/org/apache/catalina/Manager.java +++ b/tomcat/src/main/java/org/apache/catalina/Manager.java @@ -1,18 +1,15 @@ package org.apache.catalina; -import jakarta.servlet.http.HttpSession; - import java.io.IOException; +import org.apache.coyote.http11.Session; /** - * A Manager manages the pool of Sessions that are associated with a - * particular Container. Different Manager implementations may support - * value-added features such as the persistent storage of session data, - * as well as migrating sessions for distributable web applications. + * A Manager manages the pool of Sessions that are associated with a particular Container. Different Manager + * implementations may support value-added features such as the persistent storage of session data, as well as migrating + * sessions for distributable web applications. *

- * In order for a Manager implementation to successfully operate - * with a Context implementation that implements reloading, it - * must obey the following constraints: + * In order for a Manager implementation to successfully operate with a Context implementation + * that implements reloading, it must obey the following constraints: *

    *
  • Must implement Lifecycle so that the Context can indicate * that a restart is required. @@ -29,28 +26,23 @@ public interface Manager { * * @param session Session to be added */ - void add(HttpSession session); + void add(Session session); /** - * Return the active Session, associated with this Manager, with the - * specified session id (if any); otherwise return null. + * Return the active Session, associated with this Manager, with the specified session id (if any); otherwise return + * null. * * @param id The session id for the session to be returned - * - * @exception IllegalStateException if a new session cannot be - * instantiated for any reason - * @exception IOException if an input/output error occurs while - * processing this request - * - * @return the request session or {@code null} if a session with the - * requested ID could not be found + * @return the request session or {@code null} if a session with the requested ID could not be found + * @throws IllegalStateException if a new session cannot be instantiated for any reason + * @throws IOException if an input/output error occurs while processing this request */ - HttpSession findSession(String id) throws IOException; + Session findSession(String id) throws IOException; /** * Remove this Session from the active Sessions for this Manager. * * @param session Session to be removed */ - void remove(HttpSession session); + void remove(Session session); } diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HeaderKey.java b/tomcat/src/main/java/org/apache/coyote/http11/HeaderKey.java new file mode 100644 index 0000000000..a98fd1f9fd --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HeaderKey.java @@ -0,0 +1,21 @@ +package org.apache.coyote.http11; + +public enum HeaderKey { + + COOKIE("Cookie"), + CONTENT_LENGTH("Content-Length"), + CONTENT_TYPE("Content-Type"), + SET_COOKIE("Set-Cookie"), + LOCATION("Location"), + ; + + private final String value; + + HeaderKey(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/Http11Processor.java b/tomcat/src/main/java/org/apache/coyote/http11/Http11Processor.java index bb14184757..53c3258fbe 100644 --- a/tomcat/src/main/java/org/apache/coyote/http11/Http11Processor.java +++ b/tomcat/src/main/java/org/apache/coyote/http11/Http11Processor.java @@ -1,16 +1,28 @@ package org.apache.coyote.http11; +import com.techcourse.db.InMemoryUserRepository; import com.techcourse.exception.UncheckedServletException; +import com.techcourse.model.User; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.apache.coyote.Processor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.net.Socket; - public class Http11Processor implements Runnable, Processor { private static final Logger log = LoggerFactory.getLogger(Http11Processor.class); + private static final SessionManager sessionManager = SessionManager.getInstance(); private final Socket connection; @@ -25,23 +37,191 @@ public void run() { } @Override - public void process(final Socket connection) { - try (final var inputStream = connection.getInputStream(); - final var outputStream = connection.getOutputStream()) { + public void process(Socket connection) { + try (InputStream inputStream = connection.getInputStream(); + OutputStream outputStream = connection.getOutputStream()) { + HttpRequest request = HttpRequestParser.parse(inputStream); + HttpResponse response = handleRequest(request); + outputStream.write(response.build().getBytes()); + outputStream.flush(); + } catch (IOException | UncheckedServletException exception) { + log.error(exception.getMessage(), exception); + } + } - final var responseBody = "Hello world!"; + private HttpResponse handleRequest(HttpRequest request) { + if (request.isGetMethod()) { + return handleGetRequest(request); + } else if (request.isPostMethod()) { + return handlePostRequest(request); + } + throw new IllegalArgumentException("처리할 수 없는 요청입니다."); + } - final var response = String.join("\r\n", - "HTTP/1.1 200 OK ", - "Content-Type: text/html;charset=utf-8 ", - "Content-Length: " + responseBody.getBytes().length + " ", - "", - responseBody); + private HttpResponse handleGetRequest(HttpRequest request) { + if (request.getPath().equals("/")) { + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.OK); + String body = buildResponseBody("/index.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/index.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + return new HttpResponse(statusLine, headers, body); + } + if (request.getPath().equals("/register")) { + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.OK); + String body = buildResponseBody("/register.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/register.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + return new HttpResponse(statusLine, headers, body); + } + if (request.getPathWithoutQueryString().equals("/login")) { + parseQueryString(request); - outputStream.write(response.getBytes()); - outputStream.flush(); - } catch (IOException | UncheckedServletException e) { - log.error(e.getMessage(), e); + if (isLoggedIn(request)) { + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.FOUND); + String body = buildResponseBody("/index.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/index.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + return new HttpResponse(statusLine, headers, body); + } + + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.OK); + String body = buildResponseBody("/login.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/login.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + return new HttpResponse(statusLine, headers, body); + } + + if (hasPath(request)) { + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.OK); + String body = buildResponseBody(request.getPathWithoutQueryString()); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue(request.getPathWithoutQueryString())); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + return new HttpResponse(statusLine, headers, body); } + throw new IllegalArgumentException("처리할 수 없는 GET 요청입니다."); + } + + private boolean hasPath(HttpRequest request) { + try { + buildPath(request.getPath()); + return true; + } catch (IllegalArgumentException exception) { + return false; + } + } + + private String buildResponseBody(String path) { + try (BufferedReader bufferedReader = Files.newBufferedReader(buildPath(path))) { + return bufferedReader.lines() + .collect(Collectors.joining("\n")) + "\n"; + } catch (IOException exception) { + return ""; + } + } + + private String buildContentTypeValue(String path) { + try { + return Files.probeContentType(buildPath(path)) + ";charset=utf-8;"; + } catch (IOException exception) { + throw new IllegalArgumentException(exception); + } + } + + private Path buildPath(String path) { + URL resource = getClass().getResource("/static" + path); + try { + return Path.of(resource.toURI()); + } catch (NullPointerException | URISyntaxException exception) { + throw new IllegalArgumentException(exception); + } + } + + private String buildContentLengthValue(String body) { + return String.valueOf(body.getBytes().length); + } + + private void parseQueryString(HttpRequest request) { + Map queryString = request.getQueryString(); + if (!queryString.containsKey("account") || !queryString.containsKey("password")) { + return; + } + + Optional user = InMemoryUserRepository.findByAccount(queryString.get("account")); + if (user.isPresent() && user.get().checkPassword(queryString.get("password"))) { + log.info("user : {}", user.get()); + } + } + + private boolean isLoggedIn(HttpRequest request) { + Optional jsessionid = request.findCookieByName("JSESSIONID"); + if (jsessionid.isEmpty()) { + return false; + } + Session session = sessionManager.findSession(jsessionid.get()); + return session != null; + } + + private HttpResponse handlePostRequest(HttpRequest request) { + if (request.getPath().equals("/register")) { + registerUser(request); + + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.FOUND); + String body = buildResponseBody("/index.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/index.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + headers.add(HeaderKey.LOCATION, buildLocationValue("/index.html")); + return new HttpResponse(statusLine, headers, body); + } + if (request.getPath().equals("/login")) { + Map requestBody = request.getBody(); + if (requestBody.containsKey("account") && requestBody.containsKey("password")) { + Optional user = InMemoryUserRepository.findByAccount(requestBody.get("account")); + if (user.isPresent() && user.get().checkPassword(requestBody.get("password"))) { + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.FOUND); + String body = buildResponseBody("/index.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.SET_COOKIE, buildSetCookieValue(user.get())); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/index.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + headers.add(HeaderKey.LOCATION, buildLocationValue("/index.html")); + return new HttpResponse(statusLine, headers, ""); + } + } + + StatusLine statusLine = new StatusLine(request.getProtocolVersion(), Status.FOUND); + String body = buildResponseBody("/401.html"); + HttpHeaders headers = new HttpHeaders(); + headers.add(HeaderKey.CONTENT_TYPE, buildContentTypeValue("/401.html")); + headers.add(HeaderKey.CONTENT_LENGTH, buildContentLengthValue(body)); + headers.add(HeaderKey.LOCATION, buildLocationValue("/401.html")); + return new HttpResponse(statusLine, headers, body); + } + + throw new IllegalArgumentException("처리할 수 없는 POST 요청입니다."); + } + + private void registerUser(HttpRequest request) { + Map requestBody = request.getBody(); + String account = requestBody.get("account"); + String password = requestBody.get("password"); + String email = requestBody.get("email"); + InMemoryUserRepository.save(new User(account, password, email)); + } + + private String buildLocationValue(String path) { + return "http://localhost:8080" + path; + } + + private String buildSetCookieValue(User user) { + Session session = Session.create(); + session.setAttribute("user", user); + sessionManager.add(session); + return "new_id=" + session.getId() + "; Max-Age=2592000"; } } diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HttpCookies.java b/tomcat/src/main/java/org/apache/coyote/http11/HttpCookies.java new file mode 100644 index 0000000000..48bfcd326d --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HttpCookies.java @@ -0,0 +1,29 @@ +package org.apache.coyote.http11; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +public class HttpCookies { + + private final Map fields; + + public HttpCookies() { + this.fields = new HashMap<>(); + } + + public HttpCookies(String value) { + this.fields = Arrays.stream(value.split("; ")) + .map(part -> part.split("=", 2)) + .collect(Collectors.toMap(part -> part[0], part -> part[1])); + } + + public Optional findByName(String name) { + return fields.entrySet().stream() + .filter(entry -> entry.getKey().equals(name)) + .map(Map.Entry::getValue) + .findAny(); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HttpHeaders.java b/tomcat/src/main/java/org/apache/coyote/http11/HttpHeaders.java new file mode 100644 index 0000000000..dcaf1c7566 --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HttpHeaders.java @@ -0,0 +1,61 @@ +package org.apache.coyote.http11; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.stream.Collectors; + +public class HttpHeaders { + + private final Map fields; + + public HttpHeaders() { + this.fields = new HashMap<>(); + } + + public void add(String headerLine) { + String[] parts = headerLine.split(": ", 2); + add(parts[0], parts[1]); + } + + public void add(String name, String value) { + fields.put(name, value); + } + + public void add(HeaderKey headerKey, String value) { + add(headerKey.getValue(), value); + } + + public Optional findByName(HeaderKey headerKey) { + return fields.entrySet().stream() + .filter(entry -> entry.getKey().equals(headerKey.getValue())) + .map(Entry::getValue) + .findAny(); + } + + public Optional findCookieByName(String name) { + Optional rawCookies = findByName(HeaderKey.COOKIE); + if (rawCookies.isEmpty()) { + return Optional.empty(); + } + + HttpCookies cookies = new HttpCookies(rawCookies.get()); + return cookies.findByName(name); + } + + public int getContentLength() { + return Integer.parseInt(findByName(HeaderKey.CONTENT_LENGTH).orElse("0")); + } + + public String build() { + return fields.entrySet().stream() + .map(entry -> entry.getKey() + ": " + entry.getValue()) + .collect(Collectors.joining("\r\n")); + } + + @Override + public String toString() { + return build(); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HttpRequest.java b/tomcat/src/main/java/org/apache/coyote/http11/HttpRequest.java new file mode 100644 index 0000000000..c861eec88e --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HttpRequest.java @@ -0,0 +1,73 @@ +package org.apache.coyote.http11; + +import java.util.Arrays; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +public class HttpRequest { + + private final RequestLine requestLine; + private final HttpHeaders headers; + private String body; + + public HttpRequest(String rawRequestLine, HttpHeaders headers, String body) { + this.requestLine = new RequestLine(rawRequestLine); + this.headers = headers; + this.body = body; + } + + public boolean isGetMethod() { + return requestLine.getMethod().isGet(); + } + + public boolean isPostMethod() { + return requestLine.getMethod().isPost(); + } + + public Optional findCookieByName(String name) { + return headers.findCookieByName(name); + } + + public String getPath() { + return requestLine.getPath(); + } + + public String getPathWithoutQueryString() { + return getPath().split("\\?")[0]; + } + + public Map getQueryString() { + if (getPath().contains("?")) { + String queryString = getPath().substring(getPathWithoutQueryString().length()); + + return Arrays.stream(queryString.split("&")) + .map(query -> query.split("=", 2)) + .collect(Collectors.toMap(parts -> parts[0], parts -> parts[1])); + } + return Map.of(); + } + + public String getProtocolVersion() { + return requestLine.getProtocolVersion(); + } + + public Map getBody() { + if (body.isEmpty()) { + return Map.of(); + } + + return Arrays.stream(body.split("&")) + .map(query -> query.split("=", 2)) + .collect(Collectors.toMap(parts -> parts[0], parts -> parts[1])); + } + + public String build() { + return requestLine.build() + "\r\n" + headers.build() + "\r\n\r\n" + body; + } + + @Override + public String toString() { + return build(); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HttpRequestMethod.java b/tomcat/src/main/java/org/apache/coyote/http11/HttpRequestMethod.java new file mode 100644 index 0000000000..cf3dd64ecf --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HttpRequestMethod.java @@ -0,0 +1,16 @@ +package org.apache.coyote.http11; + +public enum HttpRequestMethod { + + GET, + POST, + ; + + public boolean isGet() { + return this == GET; + } + + public boolean isPost() { + return this == POST; + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HttpRequestParser.java b/tomcat/src/main/java/org/apache/coyote/http11/HttpRequestParser.java new file mode 100644 index 0000000000..e2d6305824 --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HttpRequestParser.java @@ -0,0 +1,27 @@ +package org.apache.coyote.http11; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class HttpRequestParser { + + public static HttpRequest parse(InputStream inputStream) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + + String requestLine = bufferedReader.readLine(); + + HttpHeaders headers = new HttpHeaders(); + bufferedReader.lines() + .takeWhile(headerLine -> !headerLine.isEmpty()) + .forEach(headers::add); + + int contentLength = headers.getContentLength(); + char[] rawBody = new char[contentLength]; + bufferedReader.read(rawBody, 0, contentLength); + String body = new String(rawBody); + + return new HttpRequest(requestLine, headers, body); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/HttpResponse.java b/tomcat/src/main/java/org/apache/coyote/http11/HttpResponse.java new file mode 100644 index 0000000000..3ba7894c1c --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/HttpResponse.java @@ -0,0 +1,28 @@ +package org.apache.coyote.http11; + +public class HttpResponse { + + private final StatusLine statusLine; + private final HttpHeaders headers; + private String body; + + public HttpResponse(StatusLine statusLine, HttpHeaders headers, String body) { + this.statusLine = statusLine; + this.headers = headers; + this.body = body; + } + + public HttpResponse(StatusLine statusLine, HttpHeaders headers) { + this.statusLine = statusLine; + this.headers = headers; + } + + public String build() { + return statusLine + "\r\n" + headers + "\r\n\r\n" + body; + } + + @Override + public String toString() { + return build(); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/RequestLine.java b/tomcat/src/main/java/org/apache/coyote/http11/RequestLine.java new file mode 100644 index 0000000000..1c092013d8 --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/RequestLine.java @@ -0,0 +1,31 @@ +package org.apache.coyote.http11; + +public class RequestLine { + + private final HttpRequestMethod method; + private final String path; + private final String protocolVersion; + + public RequestLine(String rawRequestLine) { + String[] parts = rawRequestLine.split(" ", 3); + this.method = HttpRequestMethod.valueOf(parts[0]); + this.path = parts[1]; + this.protocolVersion = parts[2]; + } + + public HttpRequestMethod getMethod() { + return method; + } + + public String getPath() { + return path; + } + + public String getProtocolVersion() { + return protocolVersion; + } + + public String build() { + return method + " " + path + " " + protocolVersion; + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/Session.java b/tomcat/src/main/java/org/apache/coyote/http11/Session.java new file mode 100644 index 0000000000..25824d72a7 --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/Session.java @@ -0,0 +1,42 @@ +package org.apache.coyote.http11; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class Session { + + private final String id; + private final Map values = new HashMap<>(); + + public Session(String id) { + this.id = id; + } + + public static Session create() { + return new Session(UUID.randomUUID().toString()); + } + + public String getId() { + return id; + } + + public Object getAttribute(String name) { + if (values.containsKey(name)) { + return values.get(name); + } + throw new IllegalArgumentException("세션 속성을 찾을 수 없습니다. : " + name); + } + + public void setAttribute(String name, Object value) { + values.put(name, value); + } + + public void removeAttribute(String name) { + values.remove(name); + } + + public void invalidate() { + values.clear(); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/SessionManager.java b/tomcat/src/main/java/org/apache/coyote/http11/SessionManager.java new file mode 100644 index 0000000000..c5b4260015 --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/SessionManager.java @@ -0,0 +1,37 @@ +package org.apache.coyote.http11; + +import java.util.HashMap; +import java.util.Map; +import org.apache.catalina.Manager; + +public class SessionManager implements Manager { + + private static final Map SESSIONS = new HashMap<>(); + + private static SessionManager INSTANCE; + + private SessionManager() { + } + + public static SessionManager getInstance() { + if (INSTANCE == null) { + INSTANCE = new SessionManager(); + } + return INSTANCE; + } + + @Override + public void add(Session session) { + SESSIONS.put(session.getId(), session); + } + + @Override + public Session findSession(String id) { + return SESSIONS.get(id); + } + + @Override + public void remove(Session session) { + SESSIONS.remove(session.getId()); + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/Status.java b/tomcat/src/main/java/org/apache/coyote/http11/Status.java new file mode 100644 index 0000000000..3e7d35fdf5 --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/Status.java @@ -0,0 +1,23 @@ +package org.apache.coyote.http11; + +public enum Status { + + OK(200, "OK"), + FOUND(302, "Found"); + + private final int code; + private final String message; + + Status(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/tomcat/src/main/java/org/apache/coyote/http11/StatusLine.java b/tomcat/src/main/java/org/apache/coyote/http11/StatusLine.java new file mode 100644 index 0000000000..79da160d7b --- /dev/null +++ b/tomcat/src/main/java/org/apache/coyote/http11/StatusLine.java @@ -0,0 +1,29 @@ +package org.apache.coyote.http11; + +public class StatusLine { + + private final String protocolVersion; + private final Status status; + + public StatusLine(String protocolVersion, Status status) { + this.protocolVersion = protocolVersion; + this.status = status; + } + + public int getStatusCode() { + return status.getCode(); + } + + public String getStatusMessage() { + return status.getMessage(); + } + + public String build() { + return protocolVersion + " " + getStatusCode() + " " + getStatusMessage(); + } + + @Override + public String toString() { + return build(); + } +} diff --git a/tomcat/src/main/resources/static/login.html b/tomcat/src/main/resources/static/login.html index f4ed9de875..bc933357f2 100644 --- a/tomcat/src/main/resources/static/login.html +++ b/tomcat/src/main/resources/static/login.html @@ -20,7 +20,7 @@

    로그인

    -
    +