- Build a simple, multi-threaded HTTP server in Java
- Gain deeper understanding of how the Internet operates
- Adhere to SOLID principles and test-driven development
- Pass acceptance tests outlined by Cob Spec
Requires Java 1.8 and Maven
1. Set the following environment variable:
export JAVA_SERVER_TOKEN='Basic YWRtaW46aHVudGVyMg=='
2. In your terminal, kill process on port 5000:
kill -9 `lsof -i :5000 | tail -1 | awk '{print $2}'`
3. Clone, compile, and package the code:
$ git clone https://github.com/malinatran/java-http-server
$ cd java-http-server
$ mvn package
From the root directory, run java -jar target/java-http-server-1.0-SNAPSHOT.jar
.
To specify a port and/or directory, you may pass in the following arguments: -p [PORT] -d [DIRECTORY]
, -p [PORT]
, or -d [DIRECTORY]
. The port and directory are optional; if not provided, default values for both will be set (to port 5000 and public
directory, respectively).
JUnit is the unit testing framework used for this project. Through the command line, run mvn test
. For acceptance tests via Cob Spec, run the server and follow instructions listed here.
Package | Purpose |
---|---|
mocks (test folder) | Includes mock objects for testing |
reader | Reads from input stream |
request | Parses incoming requests to build request objects |
resource | Has logic for handling resources |
response | Formats and builds response objects |
routing | Determines action by request type |
setup | Handles command-line UI and sets up configuration |
utility | Includes helper objects and constants |
writer | Writes to output stream |
More details about how the code is organized here.
๐ Make a pull request, submit an issue, or contact me @malinatran.