Overview
A simple HTTP/1.1 server built in Java using ServerSocket and Socket. This server supports basic HTTP methods, concurrency, and connection keep-alive. Designed for educational purposes and as a foundation for future enhancements.
Features
- Concurrency: Supports multiple concurrent connections using
ExecutorServicewith a fixed thread pool of 10 threads - Keep-Alive: Connections are kept alive for 5 seconds before timing out
- Compression: Supports gzip encoding for responses
- File Operations: Read and write files in the
/files/directory - Authentication: Basic authentication support
API Endpoints
GET
/
Root endpoint
200 OK with no body
GET
/user-agent
Returns the user-agent of the client
200 OK
GET
/echo/{str}
Returns the string
{str} as the response body
200 OK
Headers:
Accept-Encoding: gzip - Compresses response using gzip
Response includes
Content-Encoding: gzip header
GET
/file/{file_name}
Reads the contents of the specified file and returns it as the response body
200 OK on success
404 Not Found when file doesn't exist
Supports gzip compression
POST
/file/{file_name}
Writes the body of the POST request to a file in the
/files/ directory
201 Created
POST
/register
Requires a username and password in JSON body to register a user
201 Created if user is successfully registered
400 Bad Request if username is already taken or JSON format is incorrect
GET
/basic
Requires an Authorization header with Basic scheme (username and password encoded in Base64)
200 OK if authentication is successful
401 Unauthorized if authentication fails
Error Responses
HTTP version is not HTTP/1.1
505 HTTP Version Not Supported
All other unmatched requests
404 Not Found
Future Features
Coming Soon: SSL/TLS support for secure connections