Skip to content

Commit

Permalink
feat: Part 7 - CSS 지원하기
Browse files Browse the repository at this point in the history
.css 확장자로 끝나는 요청에 대해 response header의 content-type 값을 text/css로 전달
  • Loading branch information
blossun committed Oct 8, 2020
1 parent be866f0 commit 3f49561
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public void run() {
byte[] body = sb.toString().getBytes();
response200Header(dos, body.length);
responseBody(dos, body);
return ;
}

if (url.endsWith(".css")) {
byte[] body = Files.readAllBytes(new File("./webapp" + url).toPath());
response200CssHeader(dos, body.length);
responseBody(dos, body);
return ;
}

responseResource(dos, url);
Expand Down Expand Up @@ -166,6 +174,17 @@ private void response200Header(DataOutputStream dos, int lengthOfBodyContent) {
}
}

private void response200CssHeader(DataOutputStream dos, int lengthOfBodyContent) {
try {
dos.writeBytes("HTTP/1.1 200 OK \r\n");
dos.writeBytes("Content-Type: text/css\r\n");
dos.writeBytes("Content-Length: " + lengthOfBodyContent + "\r\n");
dos.writeBytes("\r\n");
} catch (IOException e) {
e.printStackTrace();
}
}

private void responseBody(DataOutputStream dos, byte[] body) {
try {
dos.write(body, 0, body.length);
Expand Down

0 comments on commit 3f49561

Please sign in to comment.