This is part of codecrafters.io's
"Build Your Own HTTP server" Challenge
Had fun building this one.
- Ensure you have
go (1.19)
installed locally - Run
./your_server.sh
to run the HttpServer which is implemented inapp/server.go
. - Or run
make build
ormake test
Request
$ curl -v http://localhost:4221
Response
HTTP/1.1 200 OK
Content-Type: text/plain
Request
$ curl -v http://localhost:4221/echo/abc
Response
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 3
abc
Request
$ curl -v --header "User-Agent: foobar/1.2.3" http://localhost:4221/user-agent
Response
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 12
foobar/1.2.3
Requests
$ (sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc localhost 4221 &
$ (sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc localhost 4221 &
$ (sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc localhost 4221 &
Responses
HTTP/1.1 200 OK
Content-Type: text/plain
HTTP/1.1 200 OK
Content-Type: text/plain
HTTP/1.1 200 OK
Content-Type: text/plain
Request 1
$ echo -n 'Hello, World!' > $TMPDIR/foo
$ curl -i http://localhost:4221/files/foo
Response 1
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 13
Hello, World!
Request 2
$ curl -i http://localhost:4221/files/non_existant_file
Response 2
HTTP/1.1 404 Not Found
Content-Type: text/plain
File not found
Request 1
curl -v --data "12345" -H "Content-Type: application/octet-stream" http://localhost:4221/files/file_123
Response 1
HTTP/1.1 201 Created
Request 2
curl -i http://localhost:4221/files/file_123
Response 2
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 5
12345
Request
curl -v -H "Accept-Encoding: gzip" http://localhost:4221/echo/abc
Response (formatted)
HTTP/1.1 200 OK
Content-Length: 27
Content-Encoding: gzip
Content-Type: text/plain
{ [27 bytes data]
100 27 100 27 0 0 4373 0 --:--:-- --:--:-- --:--:-- 4500
* Connection #0 to host localhost left intact
00000000 1f 8b 08 00 00 00 00 00 00 ff 4a 4c 4a 06 04 00 |..........JLJ...|
00000010 00 ff ff c2 41 24 35 03 00 00 00 |....A$5....|
0000001b