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

Commit

Permalink
ready for prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Jul 28, 2022
1 parent cd7e2c9 commit 06397e4
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<h3>SimpleHttpServer</h3>
<h5>A simple and efficient HTTP server for Java</h5>
<div>
<a href="https://docs.katsute.dev/simplehttpserver">Documentation</a>
<a href="https://github.com/KatsuteDev/simplehttpserver/blob/main/setup.md#readme">Setup</a>
<a href="https://docs.katsute.dev/simplehttpserver5">Documentation</a>
<br>
<a href="https://mvnrepository.com/artifact/dev.katsute/simplehttpserver">Maven Central</a>
Expand All @@ -19,7 +17,7 @@

<br>

> ⚠️ 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.

Expand All @@ -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(){
Expand All @@ -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<String,String> cookies = exchange.getCookies();
Expand All @@ -86,23 +86,24 @@ 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

```java
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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.katsute</groupId>
<artifactId>simplehttpserver</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-RC-1</version>

<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ public synchronized final void close(){

//


@Override
public String toString(){
return "SimpleHttpExchange{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public synchronized final void setExecutor(final Executor executor){
server.setExecutor(executor);
}


//

@Override
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -247,7 +245,6 @@ public synchronized final void stop(final int delay){

// endregion


@Override
public String toString(){
return "SimpleHttpsServer{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ final byte[] getBytes(final String path){

//


@Override
public String toString(){
return "DirectoryEntry{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ final boolean isExpired(){

//


@Override
public String toString(){
return "FileEntry{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public final void handle(final SimpleHttpExchange exchange) throws IOException {

//


@Override
public String toString(){
return "ThrottledHandler{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 06397e4

Please sign in to comment.