This is a simple HTTP server written in Go that handles various types of requests and supports concurrent connections.
- Handles GET and POST requests
- Supports concurrent connections
- Implements several endpoints:
- Root endpoint (
/
) - Echo endpoint (
/echo/<message>
) - User-Agent endpoint (
/user-agent
) - File handling endpoints (
/files/<filename>
) - Supports gzip compression for responses
- Logs incoming requests and their statuses
- Go 1.16 or higher
-
Clone this repository: git clone https://github.com/helioLJ/http-server-go.git cd http-server-go
-
Build the server: ./start_server.sh
Run the server using the start script:
./start_server.sh [--directory ]
The --directory
flag is optional and specifies the directory for file operations. If not provided, the current directory will be used.
-
Root Endpoint (
/
)- Returns a 200 OK status with an empty body.
-
Echo Endpoint (
/echo/<message>
)- Returns the
<message>
in the response body.
- Returns the
-
User-Agent Endpoint (
/user-agent
)- Returns the User-Agent header from the request.
-
File Handling Endpoints (
/files/<filename>
)- GET: Retrieves the content of the specified file.
- POST: Creates a new file with the specified name and content.
The server supports handling multiple connections concurrently. You can test this using the provided concurrent_connections.sh
script:
./concurrent_connections.sh
This script sends three concurrent requests to the server.
The server listens on port 4221 by default. To change this, modify the net.Listen()
call in the main()
function of server.go
.
The server logs each request with the following information:
- Timestamp
- Remote address
- HTTP method
- Requested path
- Response status
Logs are printed to the console.
-
Implement unit tests for all major functions:
- Test request handling for different endpoints
- Test file operations
- Test concurrent connections
- Test gzip compression
-
Add support for HTTPS
-
Implement request logging to a file
-
Add configuration file support for server settings
-
Implement basic authentication for certain endpoints
-
Add support for serving static files
-
Implement rate limiting
-
Add support for WebSocket connections
-
Implement a simple routing system for easier endpoint management
-
Add support for JSON responses
Contributions are welcome! Please feel free to submit a Pull Request.