From 06397e4c3ca6ab958f16d8ad55c000242a5ff0af Mon Sep 17 00:00:00 2001
From: Katsute <58778985+Katsute@users.noreply.github.com>
Date: Thu, 28 Jul 2022 16:27:21 -0400
Subject: [PATCH] ready for prerelease
---
.github/ISSUE_TEMPLATE/bug.yml | 2 +-
README.md | 37 ++++++++++---------
pom.xml | 2 +-
.../SimpleHttpExchangeImpl.java | 1 -
.../SimpleHttpsServerImpl.java | 3 --
.../simplehttpserver/handler/SSEHandler.java | 1 -
.../handler/file/DirectoryEntry.java | 1 -
.../handler/file/FileEntry.java | 1 -
.../handler/throttler/ThrottledHandler.java | 1 -
.../exchange/ExchangeSendTests.java | 4 +-
.../exchange/SessionTests.java | 2 +-
.../simplehttpserver/handler/SSETests.java | 2 +-
.../handler/file/FileHandlerFileTests.java | 1 -
13 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml
index 990ae2c..b54b8aa 100644
--- a/.github/ISSUE_TEMPLATE/bug.yml
+++ b/.github/ISSUE_TEMPLATE/bug.yml
@@ -9,7 +9,7 @@ body:
Before opening a bug report please check that your issue was not already discussed in the following:
* [Issues](https://github.com/KatsuteDev/simplehttpserver/issues?q=is%3Aissue+is%3Aopen+label%3Abug%2C%22critical+bug%22)
- * [Documentation](https://docs.katsute.dev/simplehttpserver)
+ * [Documentation](https://docs.katsute.dev/simplehttpserver5)
Please also check that:
diff --git a/README.md b/README.md
index cc2a366..75146c0 100644
--- a/README.md
+++ b/README.md
@@ -5,9 +5,7 @@
SimpleHttpServer
A simple and efficient HTTP server for Java
-
Documentation
- •
-
Setup
+
Documentation
Maven Central
•
@@ -19,7 +17,7 @@
-> ⚠️ simplehttpserver5 is not compatible with any previous version of [simplehttpserver](https://github.com/Ktt-Development/simplehttpserver)
+> ⚠️ simplehttpserver5 is not compatible with any previous version of [simplehttpserver](https://github.com/Ktt-Development/simplehttpserver).
Simplified httpserver experience for Java 8. Includes extensible servers and handlers for complex operations.
@@ -38,16 +36,18 @@ Compiled binaries can be installed from:
- GitHub Packages
- [Releases](https://github.com/KatsuteDev/simplehttpserver/releases)
+Refer to the [documentation](https://docs.katsute.dev/simplehttpserver5) to learn how to use servers and handlers.
+
## ✨ Features
### ✔️ Complicated tasks made easy
Simplified exchange methods for:
- - Parsing HTTP `GET`/`POST` with `multipart/form-data` support.
- - Output stream writing with `#send`.
+ - Parsing `GET`/`POST` requests, including `multipart/form-data` support.
+ - Accessing cookies.
+ - Sending byte arrays, strings, and files to clients.
- Sending gzip compressed responses.
- - Sending files
```java
SimpleHttpHandler handler = new SimpleHttpHandler(){
@@ -56,26 +56,26 @@ SimpleHttpHandler handler = new SimpleHttpHandler(){
Map POST = exchange.getPostMap();
MultipartFormData form = exchange.getMultipartFormData();
Record record = form.getRecord("record");
- FileRecord file = (FileRecord) form.getRecord("file");
+ FileRecord file = form.getRecord("file").asFile();
exchange.send(new File("OK.png"), true);
}
};
```
-### ⭐ Extended Features
+### ⭐ More Features
-Support for:
+Features not included with a regular HTTP server:
- - HTTP Cookies
- - HTTP Sessions
+ - Cookies
+ - Sessions
- Multithreaded Servers
```java
SimpleHttpServer server = new SimpleHttpServer(8080);
server.setHttpSessionHandler(new HttpSessionHandler());
-HttpHandler handler = new HttpHandler(){
+SimpleHttpHandler handler = new SimpleHttpHandler(){
@Override
- public void handle(HttpExchange exchange){
+ public void handle(SimpleHttpExchange exchange){
HttpSession session = server.getHttpSession(exchange);
String session_id = session.getSessionID();
Map
cookies = exchange.getCookies();
@@ -86,12 +86,13 @@ HttpHandler handler = new HttpHandler(){
### 🌐 Simplified Handlers
-Easy to use handlers:
+Simple and extensible request handlers:
- Redirect Handler
- Predicate Handler
+ - Root `/` Handler
- File Handler
- - Server-Sent-Events Handler
+ - Server-Sent-Events (SSE) Handler
- Temporary Handler
- Throttled Handler
@@ -99,10 +100,10 @@ Easy to use handlers:
RedirectHandler redirect = new RedirectHandler("https://github.com/");
FileHandler fileHandler = new FileHandler();
fileHandler.addFile(new File("index.html"));
-fileHandler.addDirectory(new File("/site"))
+fileHandler.addDirectory(new File("/site"));
SSEHandler SSE = new SSEHandler();
SSE.push("Server sent events!");
-ThrottledHandler throttled = new ThrottledHandler(new HttpHandler(), new ServerExchangeThrottler())
+ThrottledHandler throttled = new ThrottledHandler(new ServerExchangeThrottler(), new HttpHandler());
```
## 👨💻 Contributing
diff --git a/pom.xml b/pom.xml
index 3ee5ce5..2c0c08d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.katsute
simplehttpserver
- 5.0.0-SNAPSHOT
+ 5.0.0-RC-1
diff --git a/src/main/java/dev/katsute/simplehttpserver/SimpleHttpExchangeImpl.java b/src/main/java/dev/katsute/simplehttpserver/SimpleHttpExchangeImpl.java
index 21fd2af..f7f77cb 100644
--- a/src/main/java/dev/katsute/simplehttpserver/SimpleHttpExchangeImpl.java
+++ b/src/main/java/dev/katsute/simplehttpserver/SimpleHttpExchangeImpl.java
@@ -425,7 +425,6 @@ public synchronized final void close(){
//
-
@Override
public String toString(){
return "SimpleHttpExchange{" +
diff --git a/src/main/java/dev/katsute/simplehttpserver/SimpleHttpsServerImpl.java b/src/main/java/dev/katsute/simplehttpserver/SimpleHttpsServerImpl.java
index a93fc32..ee2cb6b 100644
--- a/src/main/java/dev/katsute/simplehttpserver/SimpleHttpsServerImpl.java
+++ b/src/main/java/dev/katsute/simplehttpserver/SimpleHttpsServerImpl.java
@@ -113,7 +113,6 @@ public synchronized final void setExecutor(final Executor executor){
server.setExecutor(executor);
}
-
//
@Override
@@ -146,7 +145,6 @@ public synchronized final HttpContext createContext(final String context, final
if(!ct.equals("/") && Objects.requireNonNull(handler) instanceof RootHandler)
throw new IllegalArgumentException("RootHandler can only be used at the root '/' context");
-
final HttpContext hc = server.createContext(ct);
if(sessionHandler != null){
@@ -247,7 +245,6 @@ public synchronized final void stop(final int delay){
// endregion
-
@Override
public String toString(){
return "SimpleHttpsServer{" +
diff --git a/src/main/java/dev/katsute/simplehttpserver/handler/SSEHandler.java b/src/main/java/dev/katsute/simplehttpserver/handler/SSEHandler.java
index 20f3da0..82b2c19 100644
--- a/src/main/java/dev/katsute/simplehttpserver/handler/SSEHandler.java
+++ b/src/main/java/dev/katsute/simplehttpserver/handler/SSEHandler.java
@@ -16,7 +16,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
package dev.katsute.simplehttpserver.handler;
import com.sun.net.httpserver.Headers;
diff --git a/src/main/java/dev/katsute/simplehttpserver/handler/file/DirectoryEntry.java b/src/main/java/dev/katsute/simplehttpserver/handler/file/DirectoryEntry.java
index 39b851e..e883c60 100644
--- a/src/main/java/dev/katsute/simplehttpserver/handler/file/DirectoryEntry.java
+++ b/src/main/java/dev/katsute/simplehttpserver/handler/file/DirectoryEntry.java
@@ -149,7 +149,6 @@ final byte[] getBytes(final String path){
//
-
@Override
public String toString(){
return "DirectoryEntry{" +
diff --git a/src/main/java/dev/katsute/simplehttpserver/handler/file/FileEntry.java b/src/main/java/dev/katsute/simplehttpserver/handler/file/FileEntry.java
index 21b7d90..ac65c3e 100644
--- a/src/main/java/dev/katsute/simplehttpserver/handler/file/FileEntry.java
+++ b/src/main/java/dev/katsute/simplehttpserver/handler/file/FileEntry.java
@@ -125,7 +125,6 @@ final boolean isExpired(){
//
-
@Override
public String toString(){
return "FileEntry{" +
diff --git a/src/main/java/dev/katsute/simplehttpserver/handler/throttler/ThrottledHandler.java b/src/main/java/dev/katsute/simplehttpserver/handler/throttler/ThrottledHandler.java
index e0cf93a..57f1870 100644
--- a/src/main/java/dev/katsute/simplehttpserver/handler/throttler/ThrottledHandler.java
+++ b/src/main/java/dev/katsute/simplehttpserver/handler/throttler/ThrottledHandler.java
@@ -74,7 +74,6 @@ public final void handle(final SimpleHttpExchange exchange) throws IOException {
//
-
@Override
public String toString(){
return "ThrottledHandler{" +
diff --git a/src/test/java/dev/katsute/simplehttpserver/exchange/ExchangeSendTests.java b/src/test/java/dev/katsute/simplehttpserver/exchange/ExchangeSendTests.java
index 70af19a..21f1e17 100644
--- a/src/test/java/dev/katsute/simplehttpserver/exchange/ExchangeSendTests.java
+++ b/src/test/java/dev/katsute/simplehttpserver/exchange/ExchangeSendTests.java
@@ -13,8 +13,8 @@ final class ExchangeSendTests {
private static SimpleHttpServer server;
- private static int testCode = HttpURLConnection.HTTP_ACCEPTED;
- private static String testContent = String.valueOf(System.currentTimeMillis());
+ private static final int testCode = HttpURLConnection.HTTP_ACCEPTED;
+ private static final String testContent = String.valueOf(System.currentTimeMillis());
@TempDir
private static File dir = new File(testContent);
diff --git a/src/test/java/dev/katsute/simplehttpserver/exchange/SessionTests.java b/src/test/java/dev/katsute/simplehttpserver/exchange/SessionTests.java
index 2d0221a..ff68a17 100644
--- a/src/test/java/dev/katsute/simplehttpserver/exchange/SessionTests.java
+++ b/src/test/java/dev/katsute/simplehttpserver/exchange/SessionTests.java
@@ -10,7 +10,7 @@
final class SessionTests {
private static SimpleHttpServer server;
- private static HttpSessionHandler sh = new HttpSessionHandler();
+ private static final HttpSessionHandler sh = new HttpSessionHandler();
private static SimpleHttpExchange exchange;
diff --git a/src/test/java/dev/katsute/simplehttpserver/handler/SSETests.java b/src/test/java/dev/katsute/simplehttpserver/handler/SSETests.java
index 65bd171..f9fc0cd 100644
--- a/src/test/java/dev/katsute/simplehttpserver/handler/SSETests.java
+++ b/src/test/java/dev/katsute/simplehttpserver/handler/SSETests.java
@@ -36,7 +36,7 @@ final void testSSE() throws InterruptedException{
handler.push("event2");
handler.push("event3");
- Thread.sleep(6000);
+ Thread.sleep(6000); // must have long delay
Assertions.assertEquals("id: 2\ndata: event1\n\nid: 2\ndata: event2\n\nid: 2\ndata: event3", data.get());
}
diff --git a/src/test/java/dev/katsute/simplehttpserver/handler/file/FileHandlerFileTests.java b/src/test/java/dev/katsute/simplehttpserver/handler/file/FileHandlerFileTests.java
index 8b5341c..7aedd69 100644
--- a/src/test/java/dev/katsute/simplehttpserver/handler/file/FileHandlerFileTests.java
+++ b/src/test/java/dev/katsute/simplehttpserver/handler/file/FileHandlerFileTests.java
@@ -34,7 +34,6 @@ static void beforeAll() throws IOException{
.filter(o -> o != FileLoadingOption.CACHE)
.forEach(blop -> files.put(new File(dir, blop.name()), blop));
- // initial write
files.forEach((file, loadingOption) -> {
Assertions.assertDoesNotThrow(() -> Files.write(file.toPath(), testContent.getBytes()));
handler.addFile(file, new FileOptions.Builder().setLoadingOption(loadingOption).build());