diff --git a/src/main/java/handler/returnValueHandle/ReturnValueHandler.java b/src/main/java/handler/returnValueHandle/ReturnValueHandler.java index 4e19b44..eb65519 100644 --- a/src/main/java/handler/returnValueHandle/ReturnValueHandler.java +++ b/src/main/java/handler/returnValueHandle/ReturnValueHandler.java @@ -33,12 +33,27 @@ public void handle() throws IOException { } } + public static void responseStaticFile(DataOutputStream dos, String url) throws IOException { + byte[] body = Files.readAllBytes(new File(PREFIX + url).toPath()); + try { + dos.writeBytes("HTTP/1.1 200 OK \r\n"); + dos.writeBytes("Content-Type: text/css;charset=utf-8 \r\n"); + dos.writeBytes(String.format("Content-Length: %d \r\n", body.length)); + dos.writeBytes("\r\n"); + dos.write(body, 0, body.length); + dos.flush(); + } catch (IOException e) { + log.error(e.getMessage()); + } + } + private void response302HeaderWithCookies(DataOutputStream dos, String location, String cookie) { try { dos.writeBytes("HTTP/1.1 302 \r\n"); dos.writeBytes(String.format("Location: %s \r\n", location)); dos.writeBytes(String.format("Set-Cookie: %s \r\n", cookie)); dos.writeBytes("\r\n"); + } catch (IOException e) { log.error(e.getMessage()); } diff --git a/src/main/java/webserver/WebCat.java b/src/main/java/webserver/WebCat.java index 97073d8..0372ba1 100644 --- a/src/main/java/webserver/WebCat.java +++ b/src/main/java/webserver/WebCat.java @@ -30,9 +30,11 @@ public void run() { HttpResponse httpResponse = new HttpResponse(out); MappingUrlHandler mappingUrlHandler = new MappingUrlHandler(httpRequest.getMethod(), httpRequest.getUrl()); DataOutputStream dos = new DataOutputStream(out); + if(httpRequest.getUrl().contains(".")) { + ReturnValueHandler.responseStaticFile(dos, httpRequest.getUrl()); + } try { Object returnValue = mappingUrlHandler.invokeMethod(httpRequest, httpResponse); - //TODO 여기서 returnValue 를 resolve 하는 방식을 찾아야 한다. ReturnValueHandler returnValueHandler = new ReturnValueHandler(returnValue, dos); returnValueHandler.handle(); } catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException | InstantiationException e) {