/http-server

Fast and lightweight HTTP Server

Primary LanguageJavaBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Pure Java HTTP Server

Fast and lightweight HTTP Server

Usage

HttpServer httpServer = new HttpServerImpl(host, port);
WebHandler webHandler = new WebHandler() {
  @Override
  public HttpResponse handleQuery(HttpRequest httpRequest) {
    // Handle requests
    return HttpResponse.build(Status.NOT_FOUND);
  }
  @Override
  public InputStream toStream(File file) throws Exception {
    return new FileInputStream(file); // Convert content to input stream
  }
};
// Set relative path of content folder
webHandler.setContentFolder("WebContent");
// Add context
webHandler.getIndexMap().put("/", "/index.html");
// Set HTTP listener
httpServer.setHttpListener(webHandler);
// Connect server
httpServer.connect();

https://sergiosoriano.com/