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

Commit

Permalink
fix failing test cases, missing tostring
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Jul 27, 2022
1 parent b14f596 commit cd7e2c9
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 13 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Changelog
# Changelog

# 1.0.0

Initial Release

**Full Changelog**: https://github.com/KatsuteDev/simplehttpserver/commits/1.0.0
77 changes: 72 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
<a href="https://docs.katsute.dev/simplehttpserver">Documentation</a>
<a href="https://github.com/KatsuteDev/simplehttpserver/blob/main/setup.md#readme">Setup</a>
</div>
<br>
<div>
<a href="https://mvnrepository.com/artifact/dev.katsute/simplehttpserver">Maven Central</a>
GitHub Packages
Expand All @@ -23,7 +21,7 @@

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

- [📃 Installation](#-installation)
- [✨ Features](#-features)
Expand All @@ -32,11 +30,80 @@

## 📃 Installation

🚧 WIP
simplehttpserver5 requires at least Java 8. No additional dependencies/libraries are required.

Compiled binaries can be installed from:

- [Maven Central](https://mvnrepository.com/artifact/dev.katsute/simplehttpserver)
- GitHub Packages
- [Releases](https://github.com/KatsuteDev/simplehttpserver/releases)

## ✨ Features

🚧 WIP
### ✔️ Complicated tasks made easy

Simplified exchange methods for:

- Parsing HTTP `GET`/`POST` with `multipart/form-data` support.
- Output stream writing with `#send`.
- Sending gzip compressed responses.
- Sending files

```java
SimpleHttpHandler handler = new SimpleHttpHandler(){
@Override
public void handle(SimpleHttpExchange exchange){
Map POST = exchange.getPostMap();
MultipartFormData form = exchange.getMultipartFormData();
Record record = form.getRecord("record");
FileRecord file = (FileRecord) form.getRecord("file");
exchange.send(new File("OK.png"), true);
}
};
```

### ⭐ Extended Features

Support for:

- HTTP Cookies
- HTTP Sessions
- Multithreaded Servers

```java
SimpleHttpServer server = new SimpleHttpServer(8080);
server.setHttpSessionHandler(new HttpSessionHandler());
HttpHandler handler = new HttpHandler(){
@Override
public void handle(HttpExchange exchange){
HttpSession session = server.getHttpSession(exchange);
String session_id = session.getSessionID();
Map<String,String> cookies = exchange.getCookies();
exchange.close();
}
};
```

### 🌐 Simplified Handlers

Easy to use handlers:

- Redirect Handler
- Predicate Handler
- File Handler
- Server-Sent-Events Handler
- Temporary Handler
- Throttled Handler

```java
RedirectHandler redirect = new RedirectHandler("https://github.com/");
FileHandler fileHandler = new FileHandler();
fileHandler.addFile(new File("index.html"));
fileHandler.addDirectory(new File("/site"))
SSEHandler SSE = new SSEHandler();
SSE.push("Server sent events!");
ThrottledHandler throttled = new ThrottledHandler(new HttpHandler(), new ServerExchangeThrottler())
```

## 👨‍💻 Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ public int getMaxConnections(final SimpleHttpExchange exchange){
return 0;
}

//

@Override
public String toString(){
return "ExchangeThrottler{" +
"connections=" + connections +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,15 @@ public synchronized final int getMaxServerConnections(){
return maxConn.get();
}

//

@Override
public String toString(){
return "ServerExchangeThrottler{" +
"connections=" + connections +
", connCount=" + connCount +
", maxConn=" + maxConn +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,16 @@ public synchronized final int getMaxServerConnections(){
return maxConn.get();
}

//

@Override
public String toString(){
return "ServerSessionThrottler{" +
"sessionHandler=" + sessionHandler +
", connections=" + connections +
", connCount=" + connCount +
", maxConn=" + maxConn +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,14 @@ public int getMaxConnections(final HttpSession session, final SimpleHttpExchange
return -1;
}

//

@Override
public String toString(){
return "SessionThrottler{" +
"sessionHandler=" + sessionHandler +
", connections=" + connections +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ public final void handle(final SimpleHttpExchange exchange) throws IOException {
exchange.close();
}

//


@Override
public String toString(){
return "ThrottledHandler{" +
"handler=" + handler +
", throttler=" + throttler +
'}';
}

}
2 changes: 1 addition & 1 deletion src/test/java/dev/katsute/simplehttpserver/Requests.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static String getBody(final HttpURLConnection conn, final boolean ignoreE
}catch(final IOException e){
if(!ignoreError)
throw new UncheckedIOException(e);
else
else if(OUT.toString().isEmpty())
return null;
}
return OUT.toString().trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ final class FileHandlerDirTests {

@TempDir
private static File dir = new File(testContent);
@TempDir
private static File subdir = new File(dir, testContent);

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

final File file = new File(dir, testContent);
Files.write(file.toPath(), testContent.getBytes());
subdir = new File(dir, "sd");
Assertions.assertTrue(subdir.mkdirs());
final File walk = new File(subdir, testContent);
Files.write(walk.toPath(), testContent.getBytes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ final class FileHandlerNoWalkTests {

@TempDir
private static File dir = new File(testContent);
@TempDir
private static File subdir = new File(dir, testContent);
private static File subdir;

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

final File file = new File(dir, testContent + ".txt");
Files.write(file.toPath(), testContent.getBytes());
subdir = new File(dir, "sd");
Assertions.assertTrue(subdir.mkdirs());
final File walk = new File(subdir, testContent + ".txt");
Files.write(walk.toPath(), testContent.getBytes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ final class FileHandlerWalkTests {

@TempDir
private static File dir = new File(testContent);
@TempDir
private static File subdir = new File(dir, testContent);

private static final FileHandler handler = new FileHandler(new FileAdapter() {
Expand All @@ -33,6 +32,8 @@ static void beforeAll() throws IOException{

final File file = new File(dir, testContent + ".txt");
Files.write(file.toPath(), testContent.getBytes());
subdir = new File(dir, "sd");
Assertions.assertTrue(subdir.mkdirs());
final File walk = new File(subdir, testContent + ".txt");
Files.write(walk.toPath(), testContent.getBytes());

Expand All @@ -59,9 +60,8 @@ final void testValid(){
dir.getName() + '/' + subdir.getName() + '/' + testContent,
};

for(final String path : validPathsToTest){
for(final String path : validPathsToTest)
Assertions.assertEquals(testContent, Requests.getBody("http://localhost:8080/" + path));
}
}

@Test
Expand Down

0 comments on commit cd7e2c9

Please sign in to comment.