⚠️ simplehttpserver5 is not compatible with any previous version of simplehttpserver.
Simplified httpserver experience for Java 8. Includes extensible servers and handlers for complex operations.
This library requires at least Java 8. No additional dependencies are required.
Compiled binaries can be installed from:
Refer to the documentation to learn how to use servers and handlers.
Simplified exchange methods for:
- Parsing
GET/POSTrequests, includingmultipart/form-datasupport. - Accessing cookies.
- Sending byte arrays, strings, and files to clients.
- Sending gzip compressed responses.
SimpleHttpHandlerhandler = newSimpleHttpHandler(){
@Overridepublicvoidhandle(SimpleHttpExchangeexchange){
MapPOST = exchange.getPostMap();
MultipartFormDataform = exchange.getMultipartFormData();
Recordrecord = form.getRecord("record");
FileRecordfile = form.getRecord("file").asFile();
exchange.send(newFile("OK.png"), true);
}
};Features not included with a regular HTTP server:
- Cookies
- Sessions
- Multithreaded Servers
SimpleHttpServerserver = newSimpleHttpServer(8080);
server.setHttpSessionHandler(newHttpSessionHandler());
SimpleHttpHandlerhandler = newSimpleHttpHandler(){
@Overridepublicvoidhandle(SimpleHttpExchangeexchange){
HttpSessionsession = server.getHttpSession(exchange);
Stringsession_id = session.getSessionID();
Map<String,String> cookies = exchange.getCookies();
exchange.close();
}
};Simple and extensible request handlers:
- Redirect Handler
- Predicate Handler
- Root
/Handler - File Handler
- Server-Sent-Events (SSE) Handler
- Temporary Handler
- Timeout 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(newServerExchangeThrottler(), newHttpHandler());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.