HTTP 요청을 처리하는 웹서버를 구현한 프로그램입니다.
프로젝트를 실행시키기 위한 도구 및 프로그램
- 서버 시작은 WebServer 클래스가 담당
- 클라이언트의 요청을 받고 응답을 보내는 모든 작업은 RequestHandler 클래스가 담당
ex) 클라이언트로부터 http://localhost:8080/index.html 요청을 받았을때 요청 메세지 전체를 출력해주고 응답으로 알맞은 페이지를 보내줍니다.
응답으로 온 index.html 파일
테스트 실행방법(Shortcuts)
- IntelliJ : ⇧+ ⌃ + R
- Eclipse(STS) : ⌥ ⌘ X + T
HTTPRequestTest: 클라이언트로부터 HTTP 요청이 왔을 때 웹 서버가 요청을 올바르게 인지하고 있는지 확인하기 위한 테스트.
ex)
printAllHeader_get() : HTTP get 요청이 왔을 때 요청 헤더가 올바르게 출력되는지 확인하기 위한 테스트.
@Test
public void printAllHeader_get() throws Exception {
InputStream in = new FileInputStream(new File(testDirectory + "getRequestMessage.txt"));
httpRequest = new HttpRequest(in);
assertEquals("localhost:8080", httpRequest.getHeader("Host"));
assertEquals("keep-alive", httpRequest.getHeader("Connection"));
assertEquals("*/*", httpRequest.getHeader("Accept"));
}
- HTTPResponseTest : 웹서버가 클라이언트의 요청을 처리하여 알맞은 응답을 보내는지 확인하기 위한 테스트.
ex) createDynamicHTML() : 웹서버가 응답으로 동적인 HTML 을 생성해서 보내는지 확인하는 테스트.
@Test
public void createDynamicHTML() throws Exception {
HttpResponse response = new HttpResponse(createOutputStream("HttpResponse.txt"));
byte[] body = response.createDynamicHTML("./webapp/user/list_static.html", users);
response.responseBody(body);
}
테스트 실행 후 HttpResponse.txt 에 해당 HTML 출력확인 가능.
- Maven - 의존성 관리 프로그램
- https://medium.com/@jwb8705/web-http-%EC%9D%B4%ED%95%B4-82552992365e
- https://medium.com/@jwb8705/web-servlet-introduction-15a900f42f87
- https://medium.com/@jwb8705/web-servlet-servlet-container-b6c3a4c6549f
이 프로젝트는 MIT 허가서를 사용합니다 - LICENSE 파일에서 자세히 알아보세요.

