A custom HTTP server written in Java with support for:
- multiple virtual servers and ports
- static file serving
- routing by path prefix
- redirects
- custom error pages
- uploads and deletes
- CGI execution
- cookies and server-side sessions
- configurable request body limits
src/- Java source codewww/- default static contentuploads/- upload target used by the sample configcgi/- CGI scripts referenced by the sample configerror_pages/- custom HTTP error pagesconfig.json- server configurationrun.sh- build and start scripttests/- automated and manual test suites
- Java installed
- Bash shell
curlfor testing- Python 3 if you want to run CGI-related tests
Start the server with:
./run.shThe script removes the previous out/ directory, compiles all Java sources into out/, and launches the server with:
java -cp out MainBy default, the sample configuration binds to:
127.0.0.1:8080127.0.0.1:8081127.0.0.1:8082
The server reads config.json on startup. If you want to change how the server behaves, this is the file to edit first.
servers- list of virtual servers to starthost- IP address or host to bind toports- one or more ports for the same virtual serverserver_name- name used by the configurationclient_body_limit- maximum request body size for that servererror_pages- custom error page paths for HTTP status codesroutes- route rules for serving files, uploads, CGI, or redirects
Each route can define:
path- URL prefix to matchroot- directory to serve fromdefault_file- file returned for a directory requestmethods- allowed HTTP methodsdirectory_listing- whether directory browsing is enabledclient_body_limit- per-route upload/body limitcgi_extensions- file extensions treated as CGI scriptsredirect- target path for redirect routes
/serves files fromwww//uploadstores and removes files inuploads//cgiexecutes matching CGI scripts fromcgi//redirectsends the client to another route
{
"servers": [
{
"host": "127.0.0.1",
"ports": [8080],
"server_name": "localhost",
"client_body_limit": 5875875,
"routes": [
{
"path": "/",
"root": "www",
"default_file": "index.html",
"methods": ["GET", "DELETE", "POST"],
"directory_listing": true
}
]
}
]
}If you edit config.json, restart the server to apply the changes.
GET,POST, andDELETEhandling where enabled by route config- longest-prefix route matching
- static file downloads with MIME type detection
- directory listing when enabled
- custom
400,403,404,405,413, and500pages - multipart upload handling
- cookie support through the
SESSIDcookie - session tracking with idle expiration
- CGI polling and response handling