-
Notifications
You must be signed in to change notification settings - Fork 310
[HTTP 서버 구현하기 - 2, 3단계] 포츈(정윤성) 미션 제출합니다. #104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
75fba41
docs: 기능목록 초안 작성
unluckyjung b8f2980
refactor: AbstractController 를 구현해 한단계 더 추상화
unluckyjung fce6042
refactor: 상태코드 ENUM 변수명 변경
unluckyjung e8d44eb
docs: 기능목록 세부화
unluckyjung 74109c8
feat: HttpCookie 구현
unluckyjung 3dabb4c
feat: 예외처리 기능 구현
unluckyjung ecbd56b
faet: JSESSIONID가 없으면, Set-Cookie를 Response헤더에 넣어 반환하는 기능
unluckyjung 9614906
feat: HttpSession(s) 구현
unluckyjung 2e43319
refactor: login, register get 요청 분기 수정
unluckyjung 4da5529
feat: Session 로그인 구현
unluckyjung e770f22
refactor: 코드 포매팅 + 추상 클래스 선언
unluckyjung 3ea3a61
refactor: 로그인 성공시에만 setCookie를 요청하도록 수정
unluckyjung 4912d8f
refactor: 오탈자, post 흐름 수정
unluckyjung 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 hidden or 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 hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/nextstep/jwp/controller/AbstractController.java
This file contains hidden or 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 nextstep.jwp.controller; | ||
|
||
import java.io.IOException; | ||
import nextstep.jwp.http.HttpRequest; | ||
import nextstep.jwp.http.HttpResponse; | ||
|
||
public abstract class AbstractController implements Controller { | ||
|
||
@Override | ||
public void service(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { | ||
if (httpRequest.isPost()) { | ||
doPost(httpRequest, httpResponse); | ||
} else { | ||
doGet(httpRequest, httpResponse); | ||
} | ||
} | ||
|
||
protected void doGet(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { | ||
httpResponse.transfer(httpRequest.getUrl()); | ||
} | ||
|
||
protected void doPost(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
package nextstep.jwp.http; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class HttpCookie { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpCookie.class); | ||
|
||
private static final int COOKIE_KEY = 0; | ||
private static final int COOKIE_VALUE = 1; | ||
private final Map<String, String> cookie; | ||
|
||
public HttpCookie(final String cookieData) { | ||
cookie = setCookie(cookieData); | ||
} | ||
|
||
private Map<String, String> setCookie(final String cookieRawData) { | ||
Map<String, String> cookieMap = new HashMap<>(); | ||
String[] cookieDataSet = cookieRawData.split(";"); | ||
for (String cookieData : cookieDataSet) { | ||
cookieData = cookieData.trim(); | ||
String[] cookieDatas = cookieData.split("="); | ||
cookieMap.put(cookieDatas[COOKIE_KEY], cookieDatas[COOKIE_VALUE]); | ||
} | ||
return cookieMap; | ||
} | ||
|
||
public boolean containsKey(final String cookieKey) { | ||
return cookie.containsKey(cookieKey); | ||
} | ||
|
||
public String getCookieValueByKey(final String cookieKey) { | ||
if (!cookie.containsKey(cookieKey)) { | ||
LOGGER.error("없는 key의 쿠키정보를 찾으려고 했습니다. key = {}", cookieKey); | ||
throw new IllegalArgumentException(String.format("없는 key의 쿠키정보를 찾으려고 했습니다. key = {%s}", cookieKey)); | ||
} | ||
return cookie.get(cookieKey); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
package nextstep.jwp.http; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class HttpSession { | ||
|
||
private final Map<String, Object> values = new HashMap<>(); | ||
private final String id; | ||
|
||
public HttpSession(final String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setAttribute(final String name, final Object value) { | ||
values.put(name, value); | ||
} | ||
|
||
public Object getAttribute(final String name) { | ||
return values.get(name); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final HttpSession that = (HttpSession) o; | ||
return Objects.equals(id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
} |
This file contains hidden or 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 nextstep.jwp.http; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class HttpSessions { | ||
|
||
private static final Map<String, HttpSession> SESSIONS = new HashMap<>(); | ||
|
||
public static HttpSession getSession(final String id) { | ||
if (SESSIONS.containsKey(id)) { | ||
return SESSIONS.get(id); | ||
} | ||
HttpSession httpSession = new HttpSession(id); | ||
SESSIONS.put(id, httpSession); | ||
return httpSession; | ||
} | ||
|
||
private HttpSessions() { | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
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.
저는 keyValue[0] 이런 식으로 구현했었는데 인덱스 상수화를 하니까 읽기가 훨씬 편하네요👍