-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[톰캣 구현하기 1,2단계] 여우(조승현) 미션 제출합니다. (#314)
* docs: 레벨 1에서 할 일 정리 * study: IOStreamTest 완료하기 * feat: http request의 uri와 method 읽어오기 * feat: /index.html로 요청을 보내면 index.html 응답하기 * refactor: httpRequest를 uri별로 핸들링하는 작업 깔끔하게 분리하기 * feat: css와 js를 받는 핸들러 추가하기 * feat: login 페이지 접속시 쿼리 파라미터를 뽑아 회원 정보를 조회하는 핸들러 구현하기 * refactor: HttpResponse와 관련된 작업을 별도의 도메인으로 분리하기 * feat: 로그인 실패시 401 처리, 성공시 302 처리하는 핸들러 개발 * feat: 회원가입 작업 수행 후 index 페이지로 리다이렉트하는 핸들러 개발하기 * feat: 로그인 성공시 쿠키에 JSESSION을 등록하는 기능 개발하기 * refactor: 쿠키 값을 cookie라는 일급 컬렉션에 캡슐화하기 * feat: 로그인된 상태에서 로그인 페이지로 접속하려는 경우 index.html로 강제 리다이렉트하는 기능 개발하기 * test: 테스트의 개행 방식을 운영체제에 무관하게 수정 * docs: 관리 안하는 요구사항 문서 제거하기 * refactor: 프로세서에서 inputStream과 outputStream을 가져오는 작업을 실행하도록 변경 * refactor: StringBuilder 대신 String을 반환하도록 변경 * refactor: String.split 대신 StringTokenizer를 사용하도록 변경 * refactor: 로그인 요청으로 GET 대신 POST를 사용하도록 변경 * refactor: 로그인 성공시 / 로그인 상태로 로그인 페이지 접속시 200 + responseBody 대신 /index.html로 302 리다이렉트하도록 변경 * refactor: 패키지 정리 후 response 응답 메시지를 만드는 작업을 별도 utils 클래스로 분리 * refactor: register 작업 이후 index.html로 리다이렉트하도록 변경
- Loading branch information
Showing
26 changed files
with
960 additions
and
71 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
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
23 changes: 23 additions & 0 deletions
23
tomcat/src/main/java/org/apache/coyote/http11/handler/BasicURIHandler.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,23 @@ | ||
package org.apache.coyote.http11.handler; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class BasicURIHandler implements HttpRequestHandler { | ||
@Override | ||
public boolean support(final HttpRequest httpRequest) { | ||
return httpRequest.isMethodEqualTo("GET") && httpRequest.isUriEqualTo("/"); | ||
} | ||
|
||
@Override | ||
public void handle(final HttpRequest httpRequest, final OutputStream outputStream) throws IOException { | ||
final var responseBody = "Hello world!"; | ||
|
||
final HttpResponse httpResponse = new HttpResponse.Builder() | ||
.responseBody(responseBody) | ||
.build(outputStream); | ||
httpResponse.flush(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tomcat/src/main/java/org/apache/coyote/http11/handler/HttpAssetHandler.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,27 @@ | ||
package org.apache.coyote.http11.handler; | ||
|
||
import org.apache.coyote.http11.resource.FileHandler; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
public class HttpAssetHandler implements HttpRequestHandler { | ||
|
||
public static final String ASSETS_PATH_PREFIX = "static/assets/"; | ||
|
||
@Override | ||
public boolean support(final HttpRequest httpRequest) { | ||
return httpRequest.isAssetRequest(); | ||
} | ||
|
||
@Override | ||
public void handle(final HttpRequest httpRequest, final OutputStream outputStream) throws IOException { | ||
final HttpResponse httpResponse = new HttpResponse.Builder() | ||
.contentType("text/javascript") | ||
.responseBody(new FileHandler().readFromResourcePath(ASSETS_PATH_PREFIX + httpRequest.getEndPoint())) | ||
.build(outputStream); | ||
httpResponse.flush(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tomcat/src/main/java/org/apache/coyote/http11/handler/HttpJavascriptHandler.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,27 @@ | ||
package org.apache.coyote.http11.handler; | ||
|
||
import org.apache.coyote.http11.resource.FileHandler; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
public class HttpJavascriptHandler implements HttpRequestHandler { | ||
|
||
public static final String JAVASCRIPT_PATH_PREFIX = "static/js/"; | ||
|
||
@Override | ||
public boolean support(final HttpRequest httpRequest) { | ||
return httpRequest.isJavascriptRequest(); | ||
} | ||
|
||
@Override | ||
public void handle(final HttpRequest httpRequest, final OutputStream outputStream) throws IOException { | ||
final HttpResponse httpResponse = new HttpResponse.Builder() | ||
.contentType("text/javascript") | ||
.responseBody(new FileHandler().readFromResourcePath(JAVASCRIPT_PATH_PREFIX + httpRequest.getEndPoint())) | ||
.build(outputStream); | ||
httpResponse.flush(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tomcat/src/main/java/org/apache/coyote/http11/handler/HttpRequestHandler.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,11 @@ | ||
package org.apache.coyote.http11.handler; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
|
||
public interface HttpRequestHandler { | ||
boolean support(HttpRequest httpRequest); | ||
|
||
void handle(HttpRequest httpRequest, OutputStream outputStream) throws IOException; | ||
} |
27 changes: 27 additions & 0 deletions
27
tomcat/src/main/java/org/apache/coyote/http11/handler/IndexCSSHandler.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,27 @@ | ||
package org.apache.coyote.http11.handler; | ||
|
||
import org.apache.coyote.http11.resource.FileHandler; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
public class IndexCSSHandler implements HttpRequestHandler { | ||
|
||
public static final String CSS_PATH_PREFIX = "static/css/"; | ||
|
||
@Override | ||
public boolean support(final HttpRequest httpRequest) { | ||
return httpRequest.isMethodEqualTo("GET") && httpRequest.isUriEqualTo("/css/styles.css"); | ||
} | ||
|
||
@Override | ||
public void handle(final HttpRequest httpRequest, final OutputStream outputStream) throws IOException { | ||
final HttpResponse httpResponse = new HttpResponse.Builder() | ||
.contentType("text/css") | ||
.responseBody(new FileHandler().readFromResourcePath(CSS_PATH_PREFIX + httpRequest.getEndPoint())) | ||
.build(outputStream); | ||
httpResponse.flush(); | ||
} | ||
} |
Oops, something went wrong.