Skip to content

Commit 2fe559b

Browse files
committed
Add automatically detection of mime-type
1 parent 1504fae commit 2fe559b

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/express/http/Response.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.sun.net.httpserver.Headers;
44
import com.sun.net.httpserver.HttpExchange;
5+
import express.ExpressUtils;
56
import express.http.cookie.Cookie;
67

78
import java.io.File;
@@ -93,14 +94,14 @@ public void send(String s) {
9394

9495
/**
9596
* Send an entire file as response
97+
* The mime type will be automatically detected.
9698
*
97-
* @param file The file.
98-
* @param contentType Content type.
99+
* @param file The file.
99100
*/
100-
public void send(File file, String contentType) {
101+
public void send(File file) {
101102
if (checkIfClosed()) return;
102103
this.contentLength += file.length();
103-
this.contentType = contentType;
104+
this.contentType = ExpressUtils.getContentType(file);
104105
sendHeaders();
105106

106107
try {

src/express/middleware/Static.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ public Static(String directoryPath) {
3434
public void handle(Request req, Response res) {
3535
File reqFile = new File(PATH + req.getURI().getPath());
3636

37-
if (reqFile.exists()) {
38-
String contentType = ExpressUtils.getContentType(reqFile);
39-
res.send(reqFile, contentType);
40-
}
37+
if (reqFile.exists())
38+
res.send(reqFile);
4139
}
4240

4341

0 commit comments

Comments
 (0)