⚠️ simplehttpserver5 is not compatible with any previous version of simplehttpserver.
Simplified httpserver experience for Java 8. Includes extensible servers and handlers for complex operations.
simplehttpserver5 requires at least Java 8. No additional dependencies/libraries are required.
Compiled binaries can be installed from:
Refer to the documentation to learn how to use servers and handlers.
Simplified exchange methods for:
GET
/POST
requests, including multipart/form-data
support.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 = form.getRecord("file").asFile();
exchange.send(new File("OK.png"), true);
}
};
Features not included with a regular HTTP server:
SimpleHttpServer server = new SimpleHttpServer(8080);
server.setHttpSessionHandler(new HttpSessionHandler());
SimpleHttpHandler handler = new SimpleHttpHandler(){
@Override
public void handle(SimpleHttpExchange exchange){
HttpSession session = server.getHttpSession(exchange);
String session_id = session.getSessionID();
Map<String,String> cookies = exchange.getCookies();
exchange.close();
}
};
Simple and extensible request handlers:
/
HandlerRedirectHandler 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 ServerExchangeThrottler(), new HttpHandler());
For local tests you can use Java 8+, however only methods in the Java 8 API may be used. The src/main/java9
folder should not be marked as a source root.
Each commit automatically triggers the Java CI workflow, make sure you have actions enabled on your forks.
This library is released under the GNU General Public License (GPL) v2.0.
Java library based on the backend of my capstone project. Simplifies the Java sun http server. Updated version of simplehttpserver.