-
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단계] 테오(최우성) 미션 제출합니다. #304
Merged
Merged
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
fc81bb1
feat: URL을 통해 정적 자원들을 찾을 수 있도록 구현
woosung1223 b50186d
feat: 다양한 파일 확장자에 대해서도 응답하도록 구현
woosung1223 d34a74c
chore: NPE 방지용 favicon 추가
woosung1223 5eaf636
feat: 로그인 페이지 구현
woosung1223 4549643
fix: html content type에 charset 추가
woosung1223 86ff6e0
refactor: startLine 객체 분리
woosung1223 9bdfa1a
feat: query parameter 출력 기능 추가
woosung1223 197db66
refactor: RequestURI 객체 분리
woosung1223 af36f74
refactor: Request, Response 객체 분리
woosung1223 354787a
refactor: Handler 객체 분리
woosung1223 dbd86b6
refactor: 로깅을 담당하는 Filter 객체 분리
woosung1223 1ecc2a4
feat: 페이지를 다루는 핸들러 추상화
woosung1223 77c4d44
chore: 패키지 분리
woosung1223 fa47e27
feat: query parameter가 제대로 인식되지 않던 문제 해결
woosung1223 91cf904
refactor: 로그인 요청을 POST로 처리하도록 변경
woosung1223 e230ecf
feat: 회원가입 기능 추가
woosung1223 79d3bba
chore: 코드 리포맷
woosung1223 cedf579
chore: 코드 리포맷
woosung1223 ce09638
refactor: HttpVersion, HttpMethod를 객체로 관리
woosung1223 fee4b62
chore: 코드 리포맷
woosung1223 931bc51
refactor: 상태코드도 객체로 관리하도록 변경
woosung1223 8a36595
refactor: responseBody에서도 header, body 등을 커스텀할 수 있도록 변경
woosung1223 ec3c487
feat: 로그인 시 세션을 쿠키에 저장할 수 있도록 구현
woosung1223 570d31b
chore: 패키지 정리
woosung1223 d3ba02f
feat: 세션 처리 기능 구현
woosung1223 e78934d
chore: 코드 리포맷
woosung1223 2a4d660
refactor: SESSION ID를 로깅하도록 변경
woosung1223 a2cdb91
chore: 메소드 네이밍 수정
woosung1223 99fa106
fix: Cookie가 없을 때 NPE가 발생하지 않도록 수정
woosung1223 4a1ff62
refactor: 사용하지 않는 메소드 삭제
woosung1223 7ca2e99
test: 테스트 보완
woosung1223 d3e153f
refactor: 메소드 시그니처 수정
woosung1223 cd6c625
chore: 메소드 순서 조정
woosung1223 25f7e24
refactor: 메소드 분리
woosung1223 e384ed9
refactor: Code Smell 제거
woosung1223 31b7491
refactor: 회원가입 성공 시 Location 헤더를 통해 redirect 하도록 변경
woosung1223 f282124
refactor: 로그인 성공 혹은 실패 시 Location 헤더를 통해 redirect 하도록 변경
woosung1223 9f2f149
refactor: Content-Length를 통해 RequestBody를 읽도록 변경
woosung1223 78db48e
fix: RequestBody 파싱 방법 변경에 따른 테스트 수정
woosung1223 22d4bc1
chore: 사용하지 않는 메소드 제거
woosung1223 2fffb5b
refactor: Headers 정적 팩토리 메소드 오버로딩
woosung1223 a737164
refactor: 확장자 제거 기능은 불필요하므로 삭제, 클래스명 변경
woosung1223 e57fcf7
chore: 리소스 패키지 상수처리
woosung1223 8f85878
refactor: status code, reason phrase 분리
woosung1223 61fb186
refactor: HttpHeaders enum 정의
woosung1223 1fbeb6d
refactor: `@ParameterizedTest` 적용, 코드 중복 제거
woosung1223 48a456c
refactor: 파일 경로 enum으로 분리
woosung1223 1ed0ff3
test: 학습 테스트 추가
woosung1223 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
19 changes: 19 additions & 0 deletions
19
tomcat/src/main/java/nextstep/jwp/db/InMemorySessionRepository.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,19 @@ | ||
package nextstep.jwp.db; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class InMemorySessionRepository { | ||
|
||
private InMemorySessionRepository() { | ||
} | ||
|
||
private static final Map<Long, UUID> sessions = new ConcurrentHashMap<>(); | ||
|
||
public static UUID save(Long userId) { | ||
UUID uuid = UUID.randomUUID(); | ||
sessions.put(userId, uuid); | ||
return uuid; | ||
} | ||
} |
31 changes: 21 additions & 10 deletions
31
tomcat/src/main/java/nextstep/jwp/db/InMemoryUserRepository.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 |
---|---|---|
@@ -1,27 +1,38 @@ | ||
package nextstep.jwp.db; | ||
|
||
import nextstep.jwp.model.User; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import nextstep.jwp.model.User; | ||
|
||
public class InMemoryUserRepository { | ||
|
||
private static final Map<String, User> database = new ConcurrentHashMap<>(); | ||
private static final Map<Long, User> database = new ConcurrentHashMap<>(); | ||
|
||
private static AtomicLong counter = new AtomicLong(); | ||
|
||
static { | ||
final User user = new User(1L, "gugu", "password", "hkkang@woowahan.com"); | ||
database.put(user.getAccount(), user); | ||
final User user = new User("gugu", "password", "hkkang@woowahan.com"); | ||
database.put(counter.getAndIncrement(), user); | ||
} | ||
|
||
private InMemoryUserRepository() { | ||
} | ||
|
||
public static void save(User user) { | ||
database.put(user.getAccount(), user); | ||
database.put(counter.getAndIncrement(), user); | ||
} | ||
|
||
public static Optional<User> findByAccount(String account) { | ||
return Optional.ofNullable(database.get(account)); | ||
public static Long getIdByCredentials(String account, String password) { | ||
return database.entrySet().stream() | ||
.filter(entry -> entry.getValue().hasSameCredential(account, password)) | ||
.findFirst() | ||
.orElseThrow() | ||
.getKey(); | ||
} | ||
|
||
private InMemoryUserRepository() {} | ||
public static boolean hasSameCredential(String account, String password) { | ||
return database.values().stream() | ||
.anyMatch(user -> user.hasSameCredential(account, password)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,38 +1,39 @@ | ||
package nextstep.jwp.model; | ||
|
||
import java.util.Objects; | ||
|
||
public class User { | ||
|
||
private final Long id; | ||
private final String account; | ||
private final String password; | ||
private final String email; | ||
|
||
public User(Long id, String account, String password, String email) { | ||
this.id = id; | ||
public User(String account, String password, String email) { | ||
this.account = account; | ||
this.password = password; | ||
this.email = email; | ||
} | ||
|
||
public User(String account, String password, String email) { | ||
this(null, account, password, email); | ||
} | ||
|
||
public boolean checkPassword(String password) { | ||
return this.password.equals(password); | ||
public boolean hasSameCredential(String account, String password) { | ||
return this.account.equals(account) && this.password.equals(password); | ||
} | ||
|
||
public String getAccount() { | ||
return account; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"id=" + id + | ||
", account='" + account + '\'' + | ||
", email='" + email + '\'' + | ||
", password='" + password + '\'' + | ||
'}'; | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
User user = (User) o; | ||
return Objects.equals(account, user.account) && | ||
Objects.equals(password, user.password) && | ||
Objects.equals(email, user.email); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(account, password, email); | ||
} | ||
} |
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
7 changes: 3 additions & 4 deletions
7
tomcat/src/main/java/org/apache/catalina/connector/Connector.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
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
28 changes: 28 additions & 0 deletions
28
tomcat/src/main/java/org/apache/coyote/http11/ContentTypeParser.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,28 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ContentTypeParser { | ||
|
||
HTML("text/html;charset=utf-8"), | ||
CSS("text/css"), | ||
JS("text/javascript"), | ||
ICO("image/x-icon"); | ||
ezzanzzan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final String contentType; | ||
|
||
ContentTypeParser(String contentType) { | ||
this.contentType = contentType; | ||
} | ||
|
||
public static String parse(String path) { | ||
int commaLocation = path.lastIndexOf("."); | ||
String resourceExtension = path.substring(commaLocation + 1); | ||
|
||
return Arrays.stream(values()) | ||
.filter(value -> value.name().toLowerCase().equals(resourceExtension)) | ||
.findFirst() | ||
.orElse(HTML) | ||
.contentType; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
tomcat/src/main/java/org/apache/coyote/http11/LoggingFilter.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,25 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import org.apache.coyote.http11.message.Cookie; | ||
import org.apache.coyote.http11.message.Headers; | ||
import org.apache.coyote.http11.message.request.Request; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LoggingFilter { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoggingFilter.class); | ||
|
||
private LoggingFilter() { | ||
} | ||
|
||
public static void logUserInfoIfExists(Request request) { | ||
Headers requestHeaders = request.getHeaders(); | ||
Cookie cookie = requestHeaders.getCookie(); | ||
|
||
if (cookie.hasKey("JSESSIONID")) { | ||
String sessionId = cookie.getValue("JSESSIONID"); | ||
log.info("session {} is logged in.", sessionId); | ||
} | ||
} | ||
} |
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.
해당 학습 테스트는 고쳐지지 않은 것 같은데 시간 될 때 해보시면 좋을 거 같아요 ˙ᵕ˙ 👍🐤