-
Notifications
You must be signed in to change notification settings - Fork 309
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
[톰캣 구현하기 - 1,2단계] 주노(최준호) 미션 제출합니다. #320
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b298b80
test: IOStream 학습테스트
Choi-JJunho b0e2503
test: File 학습테스트
Choi-JJunho a3cda7d
feat: GET /index.html 응답하기
Choi-JJunho 715bb4b
feat: CSS 지원하기
Choi-JJunho 001d50d
feat: Query String 파싱
Choi-JJunho 588c23f
test: 로그인 페이지 테스트 추가
Choi-JJunho 0f5bbf4
test: css 테스트 추가
Choi-JJunho 4510d66
refactor: HttpStatus, ContentType 분리
Choi-JJunho ace86ae
feat: HTTP Status Code 302 구현
Choi-JJunho 42da21e
feat: 회원가입, 로그인 POST 구현
Choi-JJunho 0b7002d
feat: 로그인 시 Session 쿠키 저장
Choi-JJunho e8aabbd
feat: 유효한 Session으로 Login 페이지 접근 시 index로 리다이렉트
Choi-JJunho 71b0a5c
style: System.out -> log
Choi-JJunho e6b841f
test: 테스트 수정
Choi-JJunho 59a8419
style: 코드 포맷팅
Choi-JJunho 2a7e641
refactor: ContentType 파일명으로부터 구분
Choi-JJunho 4f18be7
test: login post 시 redirect로 변경
Choi-JJunho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.apache.catalina; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Session { | ||
|
||
private final String id; | ||
private final Map<String, Object> values = new HashMap<>(); | ||
|
||
public Session(final String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public Object getAttribute(final String name) { | ||
return values.get(name); | ||
} | ||
|
||
public void setAttribute(final String name, final Object value) { | ||
this.values.put(name, value); | ||
} | ||
|
||
public void removeAttribute(final String name) { | ||
this.values.remove(name); | ||
} | ||
|
||
public void invalidate() { | ||
this.values.clear(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tomcat/src/main/java/org/apache/catalina/SessionManager.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,21 @@ | ||
package org.apache.catalina; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class SessionManager { | ||
|
||
private static final Map<String, Session> SESSIONS = new HashMap<>(); | ||
|
||
public void add(final Session session) { | ||
SESSIONS.put(session.getId(), session); | ||
} | ||
|
||
public Session findSession(final String id) { | ||
return SESSIONS.get(id); | ||
} | ||
|
||
public void remove(final String id) { | ||
SESSIONS.remove(id); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tomcat/src/main/java/org/apache/coyote/http11/ContentType.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,38 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ContentType { | ||
TEXT_HTML("text/html", "html"), | ||
CSS("text/css", "css"), | ||
APPLICATION_JSON("application/json", "json"), | ||
JAVASCRIPT("application/javascript", "js"), | ||
; | ||
private static final String DEFAULT_UTF8 = "charset=utf-8"; | ||
private static final String EXT_SEPARATOR = "."; | ||
|
||
private final String type; | ||
private final String ext; | ||
|
||
ContentType(String type, String ext) { | ||
this.type = type; | ||
this.ext = ext; | ||
} | ||
|
||
public static ContentType from(String fileName) { | ||
|
||
int index = fileName.indexOf(EXT_SEPARATOR); | ||
if (index == -1) { | ||
throw new IllegalArgumentException("지원하지 않는 ContentType입니다. fileName: " + fileName); | ||
} | ||
String ext = fileName.substring(index + 1); | ||
return Arrays.stream(values()) | ||
.filter(type -> type.ext.equalsIgnoreCase(ext)) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 ContentType입니다. fileName: " + ext)); | ||
} | ||
|
||
public String getType() { | ||
return String.format("%s;%s", type, DEFAULT_UTF8); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CharSet을 이렇게 보여줄 수도 있군요 👍