-
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단계] 에단(김석호) 미션 제출합니다. (#372)
* test: FileTest 작성 * test: IOEStreamTest 작성 * feat: 정적파일 파싱 기능 구현 * feat: header 파싱 기능 분리 * feat: queryString 파싱 기능 구현 * feat: login 기능 구현 * refactor: login을 post로 변경 * refactor: fronthandler를 생성해서 정적파일을 처리하도록 변경 * refactor: fronthandler가 GET을 처리하도록 변경 * refactor: LoginMapping, LoginPageMapping으로 리팩토링 * feat: 회원가입 화면 추가 * feat: 회원가입 기능 구현 * refactor: handle 메서드에 header 추가 * feat: Cookie를 파싱하는 HttpCookie 클래스 구현 * feat: Cookie 추가 * feat: Session 추가 * refactor: 필요없는 throws 제거 * refactor: HttpMethod enum 추가 * refactor: HttpHeaders 로 추가 * refactor: 필요없는 static 제거 * refactor: BufferedReader를 try with resources로 변겨 * refactor: HttpRequest로 변경 * refactor: HttpRequest로 변경 * refactor: session 및 request 패키지 변경 * refactor: startLine 을 requestLine 으로 변경 * refactor: httpResponse 로 리팩토링 * refactor: 레거시 코드 제거 * refactor: hello world가 text로 나가도록 변경 * fix: 리다이렉트가 될 때 html이 안보이는 문제 해결 * refactor: isAlreadyLogined 메서드를 한 줄로 변경 * refactor: "/" url을 homePageMapping으로 변경 * refactor: body에 빈 공백 제거 * refactor: header관련 설정 변경 * refactor: ContentLength가 잘못나오던 문제 해결
- Loading branch information
Showing
32 changed files
with
1,058 additions
and
56 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
39 changes: 39 additions & 0 deletions
39
tomcat/src/main/java/org/apache/coyote/handler/FrontHandler.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,39 @@ | ||
package org.apache.coyote.handler; | ||
|
||
import org.apache.coyote.handler.mapping.HandlerMapping; | ||
import org.apache.coyote.handler.mapping.HomePageMapping; | ||
import org.apache.coyote.handler.mapping.LoginMapping; | ||
import org.apache.coyote.handler.mapping.LoginPageMapping; | ||
import org.apache.coyote.handler.mapping.RegisterMapping; | ||
import org.apache.coyote.handler.mapping.RegisterPageMapping; | ||
import org.apache.coyote.handler.mapping.StaticFileMapping; | ||
import org.apache.coyote.http.request.HttpRequest; | ||
import org.apache.coyote.http.response.HttpResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class FrontHandler { | ||
|
||
private static final Set<HandlerMapping> handlerMapping = new HashSet<>(); | ||
|
||
static { | ||
handlerMapping.add(new HomePageMapping()); | ||
handlerMapping.add(new StaticFileMapping()); | ||
handlerMapping.add(new LoginMapping()); | ||
handlerMapping.add(new LoginPageMapping()); | ||
handlerMapping.add(new RegisterMapping()); | ||
handlerMapping.add(new RegisterPageMapping()); | ||
} | ||
|
||
public HttpResponse handle(final HttpRequest httpRequest) throws IOException { | ||
for (final HandlerMapping mapping : handlerMapping) { | ||
if (mapping.supports(httpRequest)) { | ||
return mapping.handle(httpRequest); | ||
} | ||
} | ||
|
||
return HttpResponse.redirect("/404.html"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tomcat/src/main/java/org/apache/coyote/handler/mapping/HandlerMapping.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,13 @@ | ||
package org.apache.coyote.handler.mapping; | ||
|
||
import org.apache.coyote.http.request.HttpRequest; | ||
import org.apache.coyote.http.response.HttpResponse; | ||
|
||
import java.io.IOException; | ||
|
||
public interface HandlerMapping { | ||
|
||
boolean supports(final HttpRequest httpRequest); | ||
|
||
HttpResponse handle(final HttpRequest httpRequest) throws IOException; | ||
} |
31 changes: 31 additions & 0 deletions
31
tomcat/src/main/java/org/apache/coyote/handler/mapping/HomePageMapping.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,31 @@ | ||
package org.apache.coyote.handler.mapping; | ||
|
||
import org.apache.coyote.http.common.HttpBody; | ||
import org.apache.coyote.http.common.HttpHeaders; | ||
import org.apache.coyote.http.request.HttpRequest; | ||
import org.apache.coyote.http.response.ContentType; | ||
import org.apache.coyote.http.response.HttpResponse; | ||
import org.apache.coyote.http.response.StatusCode; | ||
import org.apache.coyote.http.response.StatusLine; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.apache.coyote.http.common.HttpHeader.CONTENT_TYPE; | ||
|
||
public class HomePageMapping implements HandlerMapping { | ||
|
||
@Override | ||
public boolean supports(final HttpRequest httpRequest) { | ||
return httpRequest.isGetRequest() && "/".equals(httpRequest.getRequestUri().getRequestUri()); | ||
} | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest httpRequest) throws IOException { | ||
return HttpResponse.builder() | ||
.statusLine(StatusLine.from(StatusCode.OK)) | ||
.httpHeaders(new HttpHeaders(Map.of(CONTENT_TYPE, ContentType.HTML.getValue()))) | ||
.body(new HttpBody("Hello world!")) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tomcat/src/main/java/org/apache/coyote/handler/mapping/LoginFilter.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,24 @@ | ||
package org.apache.coyote.handler.mapping; | ||
|
||
import org.apache.coyote.http.LoginManager; | ||
import org.apache.coyote.http.session.Session; | ||
import org.apache.coyote.http.session.SessionManager; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class LoginFilter { | ||
|
||
private static final LoginManager loginManager = new SessionManager(); | ||
|
||
protected boolean isAlreadyLogined(final String jSessionId) { | ||
return loginManager.isAlreadyLogined(jSessionId); | ||
} | ||
|
||
protected void setSession(final String jSessionId, final Map<String, String> sessionData) { | ||
final Session session = new Session(jSessionId); | ||
for (final String key : sessionData.keySet()) { | ||
session.add(key, sessionData.get(key)); | ||
} | ||
loginManager.add(session); | ||
} | ||
} |
Oops, something went wrong.