Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit cd7e2c9

Browse files
committed
fix failing test cases, missing tostring
1 parent b14f596 commit cd7e2c9

File tree

11 files changed

+139
-13
lines changed

11 files changed

+139
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# Changelog
1+
# Changelog
2+
3+
# 1.0.0
4+
5+
Initial Release
6+
7+
**Full Changelog**: https://github.com/KatsuteDev/simplehttpserver/commits/1.0.0

README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
<a href="https://docs.katsute.dev/simplehttpserver">Documentation</a>
99
1010
<a href="https://github.com/KatsuteDev/simplehttpserver/blob/main/setup.md#readme">Setup</a>
11-
</div>
1211
<br>
13-
<div>
1412
<a href="https://mvnrepository.com/artifact/dev.katsute/simplehttpserver">Maven Central</a>
1513
1614
GitHub Packages
@@ -23,7 +21,7 @@
2321

2422
> ⚠️ simplehttpserver5 is not compatible with any previous version of [simplehttpserver](https://github.com/Ktt-Development/simplehttpserver)
2523
26-
🚧 WIP
24+
Simplified httpserver experience for Java 8. Includes extensible servers and handlers for complex operations.
2725

2826
- [📃 Installation](#-installation)
2927
- [✨ Features](#-features)
@@ -32,11 +30,80 @@
3230

3331
## 📃 Installation
3432

35-
🚧 WIP
33+
simplehttpserver5 requires at least Java 8. No additional dependencies/libraries are required.
34+
35+
Compiled binaries can be installed from:
36+
37+
- [Maven Central](https://mvnrepository.com/artifact/dev.katsute/simplehttpserver)
38+
- GitHub Packages
39+
- [Releases](https://github.com/KatsuteDev/simplehttpserver/releases)
3640

3741
## ✨ Features
3842

39-
🚧 WIP
43+
### ✔️ Complicated tasks made easy
44+
45+
Simplified exchange methods for:
46+
47+
- Parsing HTTP `GET`/`POST` with `multipart/form-data` support.
48+
- Output stream writing with `#send`.
49+
- Sending gzip compressed responses.
50+
- Sending files
51+
52+
```java
53+
SimpleHttpHandler handler = new SimpleHttpHandler(){
54+
@Override
55+
public void handle(SimpleHttpExchange exchange){
56+
Map POST = exchange.getPostMap();
57+
MultipartFormData form = exchange.getMultipartFormData();
58+
Record record = form.getRecord("record");
59+
FileRecord file = (FileRecord) form.getRecord("file");
60+
exchange.send(new File("OK.png"), true);
61+
}
62+
};
63+
```
64+
65+
### ⭐ Extended Features
66+
67+
Support for:
68+
69+
- HTTP Cookies
70+
- HTTP Sessions
71+
- Multithreaded Servers
72+
73+
```java
74+
SimpleHttpServer server = new SimpleHttpServer(8080);
75+
server.setHttpSessionHandler(new HttpSessionHandler());
76+
HttpHandler handler = new HttpHandler(){
77+
@Override
78+
public void handle(HttpExchange exchange){
79+
HttpSession session = server.getHttpSession(exchange);
80+
String session_id = session.getSessionID();
81+
Map<String,String> cookies = exchange.getCookies();
82+
exchange.close();
83+
}
84+
};
85+
```
86+
87+
### 🌐 Simplified Handlers
88+
89+
Easy to use handlers:
90+
91+
- Redirect Handler
92+
- Predicate Handler
93+
- File Handler
94+
- Server-Sent-Events Handler
95+
- Temporary Handler
96+
- Throttled Handler
97+
98+
```java
99+
RedirectHandler redirect = new RedirectHandler("https://github.com/");
100+
FileHandler fileHandler = new FileHandler();
101+
fileHandler.addFile(new File("index.html"));
102+
fileHandler.addDirectory(new File("/site"))
103+
SSEHandler SSE = new SSEHandler();
104+
SSE.push("Server sent events!");
105+
ThrottledHandler throttled = new ThrottledHandler(new HttpHandler(), new ServerExchangeThrottler())
106+
```
40107

41108
## 👨‍💻 Contributing
42109

src/main/java/dev/katsute/simplehttpserver/handler/throttler/ExchangeThrottler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,13 @@ public int getMaxConnections(final SimpleHttpExchange exchange){
8080
return 0;
8181
}
8282

83+
//
84+
85+
@Override
86+
public String toString(){
87+
return "ExchangeThrottler{" +
88+
"connections=" + connections +
89+
'}';
90+
}
91+
8392
}

src/main/java/dev/katsute/simplehttpserver/handler/throttler/ServerExchangeThrottler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,15 @@ public synchronized final int getMaxServerConnections(){
161161
return maxConn.get();
162162
}
163163

164+
//
165+
166+
@Override
167+
public String toString(){
168+
return "ServerExchangeThrottler{" +
169+
"connections=" + connections +
170+
", connCount=" + connCount +
171+
", maxConn=" + maxConn +
172+
'}';
173+
}
174+
164175
}

src/main/java/dev/katsute/simplehttpserver/handler/throttler/ServerSessionThrottler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,16 @@ public synchronized final int getMaxServerConnections(){
187187
return maxConn.get();
188188
}
189189

190+
//
191+
192+
@Override
193+
public String toString(){
194+
return "ServerSessionThrottler{" +
195+
"sessionHandler=" + sessionHandler +
196+
", connections=" + connections +
197+
", connCount=" + connCount +
198+
", maxConn=" + maxConn +
199+
'}';
200+
}
190201

191202
}

src/main/java/dev/katsute/simplehttpserver/handler/throttler/SessionThrottler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,14 @@ public int getMaxConnections(final HttpSession session, final SimpleHttpExchange
102102
return -1;
103103
}
104104

105+
//
106+
107+
@Override
108+
public String toString(){
109+
return "SessionThrottler{" +
110+
"sessionHandler=" + sessionHandler +
111+
", connections=" + connections +
112+
'}';
113+
}
105114

106115
}

src/main/java/dev/katsute/simplehttpserver/handler/throttler/ThrottledHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,15 @@ public final void handle(final SimpleHttpExchange exchange) throws IOException {
7272
exchange.close();
7373
}
7474

75+
//
76+
77+
78+
@Override
79+
public String toString(){
80+
return "ThrottledHandler{" +
81+
"handler=" + handler +
82+
", throttler=" + throttler +
83+
'}';
84+
}
85+
7586
}

src/test/java/dev/katsute/simplehttpserver/Requests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static String getBody(final HttpURLConnection conn, final boolean ignoreE
5353
}catch(final IOException e){
5454
if(!ignoreError)
5555
throw new UncheckedIOException(e);
56-
else
56+
else if(OUT.toString().isEmpty())
5757
return null;
5858
}
5959
return OUT.toString().trim();

src/test/java/dev/katsute/simplehttpserver/handler/file/FileHandlerDirTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ final class FileHandlerDirTests {
1818

1919
@TempDir
2020
private static File dir = new File(testContent);
21-
@TempDir
2221
private static File subdir = new File(dir, testContent);
2322

2423
private static final FileHandler handler = new FileHandler();
@@ -31,6 +30,8 @@ static void beforeAll() throws IOException{
3130

3231
final File file = new File(dir, testContent);
3332
Files.write(file.toPath(), testContent.getBytes());
33+
subdir = new File(dir, "sd");
34+
Assertions.assertTrue(subdir.mkdirs());
3435
final File walk = new File(subdir, testContent);
3536
Files.write(walk.toPath(), testContent.getBytes());
3637

src/test/java/dev/katsute/simplehttpserver/handler/file/FileHandlerNoWalkTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ final class FileHandlerNoWalkTests {
1717

1818
@TempDir
1919
private static File dir = new File(testContent);
20-
@TempDir
21-
private static File subdir = new File(dir, testContent);
20+
private static File subdir;
2221

2322
private static final FileHandler handler = new FileHandler(new FileAdapter() {
2423
@Override
@@ -33,6 +32,8 @@ static void beforeAll() throws IOException{
3332

3433
final File file = new File(dir, testContent + ".txt");
3534
Files.write(file.toPath(), testContent.getBytes());
35+
subdir = new File(dir, "sd");
36+
Assertions.assertTrue(subdir.mkdirs());
3637
final File walk = new File(subdir, testContent + ".txt");
3738
Files.write(walk.toPath(), testContent.getBytes());
3839

0 commit comments

Comments
 (0)