
A simplified implementation of the sun http server for JDK11.
This library simplifies complex operations for both the server, exchange, and handlers.
Documentation
•
Issues
Compiled binaries can be found on Maven Central.
For projects built locally, compiled binaries can also be found in releases.
Simplified exchange methods for:
- Parsing HTTP
GET/POSTwithmultipart/form-datasupport. - Output stream writing with
#send. - Sending gzip compressed responses.
- Sending files
SimpleHttpHandlerhandler = newSimpleHttpHandler(){
@Overridepublicvoidhandle(SimpleHttpExchangeexchange){
MapPOST = exchange.getPostMap();
MultipartFormDataform = exchange.getMultipartFormData();
Recordrecord = form.getRecord("record");
FileRecordfile = (FileRecord) form.getRecord("file");
exchange.send(newFile("OK.png"), true);
}
};Out of the box support for:
- HTTP Cookies
- HTTP Sessions
- Multithreaded Servers
SimpleHttpServerserver = newSimpleHttpServer(8080);
server.setHttpSessionHandler(newHttpSessionHandler());
HttpHandlerhandler = newHttpHandler(){
@Overridepublicvoidhandle(HttpExchangeexchange){
HttpSessionsession = server.getHttpSession(exchange);
Stringsession_id = session.getSessionID();
Map<String,String> cookies = exchange.getCookies();
exchange.close();
}
};Easy to use handlers:
- Redirect Handler
- Predicate Handler
- File Handler
- Server-Sent-Events Handler
- Temporary Handler
- Throttled Handler
RedirectHandlerredirect = newRedirectHandler("https://github.com/");
FileHandlerfileHandler = newFileHandler();
fileHandler.addFile(newFile("index.html"));
fileHandler.addDirectory(newFile("/site"))
SSEHandlerSSE = newSSEHandler();
SSE.push("Server sent events!");
ThrottledHandlerthrottled = newThrottledHandler(newHttpHandler(), newServerExchangeThrottler())- Found a bug? Open a new issue.
- Want to contribute? Create a fork and open a pull request.