Skip to content
main
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Logo

SimpleHttpServer

A simplified implementation of the sun http server for JDK11.
This library simplifies complex operations for both the server, exchange, and handlers.
Docs β€’ Wiki β€’ Issues

Deploy Java CI Maven Central version license

Setup

Compiled binaries can be found on Maven Central. Maven Central

For projects built locally, compiled binaries can also be found in releases. releases

Features

πŸ“‹ 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
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"), HttpCode.HTTP_OK, true);
    }

};

οΏ½? Extended Features

Out of the box support for:

  • HTTP Cookies
  • HTTP Sessions
  • Multithreaded Servers
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
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())

About

πŸ“• SimpleHttpServer :: Simplified implementation of the sun http server :: Simplified handlers to execute complex operations

Topics

Resources

License

Languages

You can’t perform that action at this time.