This project is a custom implementation of a basic web server built with Go. It was developed as part of a coding challenge here. The server demonstrates how to handle HTTP requests and serve static files efficiently, providing a foundation for learning or extending to more complex web server features.
- Serve static files from a specified directory.
- Simple and lightweight implementation.
- Handles HTTP GET requests securely, with protections against directory traversal attacks.
- Configurable server port via command-line flags.
These instructions will help you set up and run the project on your local machine for development and testing purposes.
- You need to have Go installed on your machine (Go 1.18 or later is recommended).
- You can download and install Go from https://golang.org/dl/.
Clone the repository to your local machine:
git clone https://github.com/nullsploit01/cc-web-server.git
cd cc-web-server
Compile the project using:
go build -o ccws
To run the server, execute the compiled binary. You can specify the port using the --port (or -p) flag.
./ccws
./ccws --port 9090
Access the root endpoint to serve index.html:
curl http://localhost:8080/
Request a specific file (e.g., hello.html):
curl http://localhost:8080/hello.html
Attempt to access a non-existent file:
curl http://localhost:8080/nonexistent.html
Expected response: 404 Not Found
Attempt directory traversal (protected):
curl http://localhost:8080/../../../../etc/passwd
Expected response: 403 Forbidden
go test ./...