-
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
[톰캣 구현하기 3, 4단계] 채채(신채원) 미션 제출합니다 #485
Changes from 10 commits
fb5d66c
ee59aff
13190d3
7bb1b41
8cee023
f34b147
f600455
c8588ee
159200d
0ed222c
93e171b
ac53939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package org.apache.coyote.http11.session; | ||
package org.apache.catalina.session; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public class Session { | ||
public class HttpSession { | ||
|
||
private final String id; | ||
private final Map<String, Object> values = new HashMap<>(); | ||
private final Map<String, Object> values; | ||
|
||
public Session() { | ||
public HttpSession(final String name, final Object value) { | ||
this.id = UUID.randomUUID().toString(); | ||
values = new HashMap<>(); | ||
values.put(name, value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성자에서 값을 추가하는 이유가 무엇인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성자를 새로 생성할때마다 새로운 UUID를 주고 그외의 상황에서는 id를 바꾸거나 생성하지 않도록 하기 위해서 생성자에서 진행을 하였습니다! 만들어둔 매서드를 사용하는것이 좋겠네요..! |
||
} | ||
|
||
public String getId() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.apache.catalina.session; | ||
|
||
import org.apache.catalina.Manager; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class SessionManager implements Manager { | ||
|
||
// static! | ||
private static final Map<String, HttpSession> sessions = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
라는 요구사항이 있었는데 한번 확인 해보시면 좋을것같아요 🤔 |
||
|
||
@Override | ||
public void add(HttpSession httpSession) { | ||
sessions.put(httpSession.getId(), httpSession); | ||
} | ||
|
||
@Override | ||
public HttpSession findSession(final String id) { | ||
return sessions.get(id); | ||
} | ||
|
||
@Override | ||
public void remove(HttpSession httpSession) { | ||
sessions.remove(httpSession.getId()); | ||
} | ||
|
||
public static boolean isExist(final String id) { | ||
return sessions.containsKey(id); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,5 @@ private boolean isSameExtension(String extension) { | |
public String getContentType() { | ||
return contentType; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.apache.coyote.http11.response; | ||
|
||
import org.apache.coyote.http11.request.HttpRequest; | ||
|
||
import java.io.IOException; | ||
|
||
public interface Controller { | ||
void service(final HttpRequest request, | ||
final HttpResponse response) throws IOException; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.apache.coyote.http11.response; | ||
|
||
import org.apache.coyote.http11.ContentType; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
|
||
public class FileGetController implements Controller { | ||
|
||
@Override | ||
public void service(final HttpRequest request, | ||
final HttpResponse response) { | ||
final String resourcePath = request.getRequestLine().getRequestUrl(); | ||
final String responseBody = ResourceResolver.resolve(resourcePath); | ||
|
||
response.setStatusCode(StatusCode.OK); | ||
response.setResponseBody(ResourceResolver.resolve(resourcePath)); | ||
response.addHeader("Content-Type", ContentType.from(resourcePath).getContentType() + ";charset=utf-8"); | ||
response.addHeader("Content-Length",String.valueOf(responseBody.getBytes().length)); | ||
} | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.apache.coyote.http11.response; | ||
|
||
import org.apache.coyote.http11.ContentType; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
|
||
public class HelloController implements Controller { | ||
|
||
@Override | ||
public void service(final HttpRequest request, | ||
final HttpResponse response) { | ||
final String responseBody = "Hello world!"; | ||
|
||
response.setStatusCode(StatusCode.OK); | ||
response.setResponseBody(responseBody); | ||
response.addHeader("Content-Type", ContentType.HTML.getContentType() + ";charset=utf-8"); | ||
response.addHeader("Content-Length", String.valueOf(responseBody.getBytes().length)); | ||
} | ||
|
||
} |
This file was deleted.
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.
👍