https://github.com/sergiss/http-server
Fast and lightweight HTTP Server
https://github.com/sergiss/http-server
http-server java
Last synced: about 1 year ago
JSON representation
Fast and lightweight HTTP Server
- Host: GitHub
- URL: https://github.com/sergiss/http-server
- Owner: sergiss
- License: bsd-3-clause
- Created: 2020-10-10T17:13:41.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-03T23:11:34.000Z (almost 5 years ago)
- Last Synced: 2025-03-26T15:54:51.009Z (over 1 year ago)
- Topics: http-server, java
- Language: Java
- Homepage:
- Size: 976 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pure Java HTTP Server
Fast and lightweight HTTP Server
Usage
```java
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/