Skip to content

Commit 87a9f37

Browse files
committed
Sort project
1 parent 95001cc commit 87a9f37

File tree

13 files changed

+127
-81
lines changed

13 files changed

+127
-81
lines changed

src/express/Express.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import express.http.Request;
99
import express.http.Response;
1010

11-
import java.io.File;
1211
import java.io.IOException;
1312
import java.net.InetSocketAddress;
1413
import java.util.ArrayList;
@@ -18,7 +17,7 @@
1817
/**
1918
* @author Simon Reinisch
2019
* @implNote Core modul, don't change anything.
21-
*
20+
* <p>
2221
* An NodeJS like clone written in Java, see README for more information.
2322
*/
2423
public class Express {
@@ -234,26 +233,4 @@ public void listen(Action onStart, int port) throws IOException {
234233
}
235234
}).start();
236235
}
237-
238-
/**
239-
* This method serves an entire folder which can contains static file for your
240-
* web application, it automatically detect the content type and will send it to
241-
* the Client.
242-
* <p>
243-
* To use it simply put it in the <code>app.use()</code> method!
244-
*
245-
* @param path The root directory
246-
* @return An HttpRequest interface with the service.
247-
*/
248-
public static HttpRequest statics(String path) {
249-
return (req, res) -> {
250-
File reqFile = new File(path + req.getURI().getPath());
251-
252-
if (reqFile.exists()) {
253-
String extension = reqFile.getAbsolutePath().replaceAll("^(.*\\.|.*\\\\|.+$)", "");
254-
String contentType = ExpressUtils.getContentType(extension);
255-
res.send(reqFile, contentType);
256-
}
257-
};
258-
}
259236
}

src/express/ExpressFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Simon Reinisch
1616
* @implNote Core modul of express, don't change anything.
17-
*
17+
* <p>
1818
* Filter to handle request handling & parsing.
1919
*/
2020
public class ExpressFilter extends Filter {

src/express/ExpressUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package express;
22

33
import com.sun.net.httpserver.Headers;
4-
import express.cookie.Cookie;
4+
import express.http.cookie.Cookie;
55

66
import java.io.UnsupportedEncodingException;
77
import java.net.URI;

src/express/MIMETypes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44

55
/**
66
* @author Simon Reinisch
7-
*
7+
* <p>
88
* Full list of mime-types to handle static served files.
99
* List-link: https://www.freeformatter.com/mime-types-list.html
1010
*/
1111
public class MIMETypes {
1212

1313
private final static HashMap<String, String> MIME = new HashMap<>();
1414

15-
public static HashMap<String, String> get() {
16-
return MIME;
17-
}
18-
1915
static {
2016
MIME.put("aw", "application/applixware");
2117
MIME.put("atom", "application/atom+xml ");
@@ -709,4 +705,8 @@ public static HashMap<String, String> get() {
709705
MIME.put("yaml", "text/yaml");
710706
MIME.put("dmg", "application/x-apple-diskimage");
711707
}
708+
709+
public static HashMap<String, String> get() {
710+
return MIME;
711+
}
712712
}

src/express/http/Request.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.sun.net.httpserver.Headers;
44
import com.sun.net.httpserver.HttpExchange;
55
import express.ExpressUtils;
6-
import express.cookie.Cookie;
6+
import express.http.cookie.Cookie;
77

88
import java.io.IOException;
99
import java.io.InputStream;

src/express/http/Response.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import com.sun.net.httpserver.Headers;
44
import com.sun.net.httpserver.HttpExchange;
5-
import express.cookie.Cookie;
5+
import express.http.cookie.Cookie;
6+
import express.middleware.FormInfo;
67

78
import java.io.File;
89
import java.io.IOException;
@@ -19,6 +20,8 @@ public class Response {
1920
private final OutputStream BODY;
2021
private final Headers HEADER;
2122

23+
private FormInfo formInfo;
24+
2225
private String contentType = "text/plain";
2326
private boolean isClose = false;
2427
private long contentLength = 0;
@@ -30,6 +33,20 @@ public Response(HttpExchange exchange) {
3033
this.BODY = exchange.getResponseBody();
3134
}
3235

36+
/**
37+
* If the request was an multipart-formdata request, you can
38+
* receive over the FormInfo object serveral informations.
39+
*
40+
* @return
41+
*/
42+
public FormInfo getFormInfo() {
43+
return formInfo;
44+
}
45+
46+
public void setFormInfo(FormInfo formInfo) {
47+
this.formInfo = formInfo;
48+
}
49+
3350
/**
3451
* Set an cookie.
3552
*
@@ -42,6 +59,13 @@ public Response setCookie(Cookie cookie) {
4259
return this;
4360
}
4461

62+
/**
63+
* @return Current response status.
64+
*/
65+
public int getStatus() {
66+
return this.status;
67+
}
68+
4569
/**
4670
* Set the response-status.
4771
* Default is 200 (ok).
@@ -55,13 +79,6 @@ public Response setStatus(int status) {
5579
return this;
5680
}
5781

58-
/**
59-
* @return Current response status.
60-
*/
61-
public int getStatus() {
62-
return this.status;
63-
}
64-
6582
/**
6683
* Send an empty response (Content-Length = 0)
6784
*/

src/express/cookie/Cookie.java renamed to src/express/http/cookie/Cookie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package express.cookie;
1+
package express.http.cookie;
22

33

44
import java.time.Instant;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package express.cookie;
1+
package express.http.cookie;
22

33
/**
44
* @author Simon Reinisch
55
*/
66
public enum SameSite {
7-
STRICT, LAX
7+
STRICT, LAX
88
}

src/express/middleware/Static.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package express.middleware;
2+
3+
import express.ExpressUtils;
4+
import express.events.HttpRequest;
5+
import express.http.Request;
6+
import express.http.Response;
7+
8+
import java.io.File;
9+
10+
/**
11+
* @author Simon Reinisch
12+
* <p>
13+
* An Express-Middleware to serve static files.
14+
*/
15+
public class Static implements HttpRequest {
16+
17+
private final String PATH;
18+
19+
/**
20+
* This class serves an entire folder which can contains static file for your
21+
* web application, it automatically detect the content type and will send it to
22+
* the Client.
23+
* <p>
24+
* To use it simply put it in the <code>app.use()</code> method!
25+
*
26+
* @param directoryPath The root directory
27+
*/
28+
public Static(String directoryPath) {
29+
this.PATH = directoryPath;
30+
}
31+
32+
@Override
33+
public void handle(Request req, Response res) {
34+
File reqFile = new File(PATH + req.getURI().getPath());
35+
36+
if (reqFile.exists()) {
37+
String extension = reqFile.getAbsolutePath().replaceAll("^(.*\\.|.*\\\\|.+$)", "");
38+
String contentType = ExpressUtils.getContentType(extension);
39+
res.send(reqFile, contentType);
40+
}
41+
}
42+
}

src/test/Get.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package test;
22

33
import express.Express;
4-
import express.cookie.Cookie;
4+
import express.http.cookie.Cookie;
55

66
import java.io.IOException;
77
import java.util.HashMap;

0 commit comments

Comments
 (0)