Skip to content

PeterDeKok/codecrafters-http-server-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

progress-banner

Run

yarn install
yarn dev --directory ./files

Tests

#AT4 (Bind to a port)

curl -v http://localhost:4221/

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0

#IA4 (Respond with 200)

curl -v http://localhost:4221/

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0

#IH0 (Extract URL path)

curl -v http://localhost:4221/mango

HTTP/1.1 404 Not Found
Content-Type: text/plain
Content-Length: 0

#CN2 (Respond with body)

curl -v http://localhost:4221/echo/pineapple

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 9

pineapple

#FS3 (Read header)

curl -v http://localhost:4221/user-agent -H "User-Agent: raspberry/blueberry"

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 19

raspberry/blueberry

#EJ5 (Concurrent connections)

curl -v http://localhost:4221/ (2x)

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0

#AP6 (Return a file)

echo "Hello, World\!" > ./files/foo && curl -v http://localhost:4221/files/foo

HTTP/1.1 200 OK
Content-Length: 14
Content-Type: application/octet-stream

Hello, World!

curl -v http://localhost:4221/files/non-existent

HTTP/1.1 404 Not Found
Content-Type: text/plain
Content-Length: 0

#QV8 (Read request body)

curl -v -X POST http://localhost:4221/files/bar -H "Content-Length: 73" -H "Content-Type: application/octet-stream" -d 'orange pineapple blueberry raspberry strawberry apple raspberry raspberry' && cat ./files/bar

HTTP/1.1 201 Created
Content-Type: text/plain
Content-Length: 0
orange pineapple blueberry raspberry strawberry apple raspberry raspberry

#DF4 (HTTP Compression - Compression headers)

curl -v http://localhost:4221/echo/pear -H "Accept-Encoding: gzip" | hexdump -C

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: text/plain
Content-Length: 24

00000000  1f 8b 08 00 00 00 00 00  00 13 2b 48 4d 2c 02 00  |..........+HM,..|
00000010  bd 3c 8a c6 04 00 00 00                           |.<......|

curl -v http://localhost:4221/echo/pear -H "Accept-Encoding: invalid-encoding"

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 4

pear

#IJ8 (HTTP Compression - Multiple compression schemes)

curl -v http://localhost:4221/echo/apple -H "Accept-Encoding: encoding-1, gzip, encoding-2" | hexdump -C

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: text/plain
Content-Length: 25

00000000  1f 8b 08 00 00 00 00 00  00 13 4b 2c 28 c8 49 05  |..........K,(.I.|
00000010  00 50 d0 2e a9 05 00 00  00                       |.P.......|

curl -v http://localhost:4221/echo/apple -H "Accept-Encoding: encoding-1, encoding-2"

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 5

apple

#CR8 (HTTP Compression - Gzip compression)

curl -v http://localhost:4221/echo/banana -H "Accept-Encoding: gzip" | hexdump -C

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: text/plain
Content-Length: 26

00000000  1f 8b 08 00 00 00 00 00  00 13 4b 4a cc 4b cc 4b  |..........KJ.K.K|
00000010  04 00 cf 67 8b 03 06 00  00 00                    |...g......|

Stage #AG9 (Persistent Connections - Persistent connections)

curl --http1.1 -v http://localhost:4221/ --next http://localhost:4221/user-agent -H "User-Agent: strawberry/apple"

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 16

strawberry/apple

#UL1 (Persistent Connections - Concurrent persistent connections)

curl --http1.1 -v http://localhost:4221/user-agent -H "User-Agent: orange/pineapple" --next http://localhost:4221/user-agent -H "User-Agent: pear/apple-banana" (2x)

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 16

orange/pineapple
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 17

pear/apple-banana
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 16

orange/pineapple
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 17

pear/apple-banana

#KH7 (Persistent Connections - Connection closure)

curl --http1.1 -v http://localhost:4221/ --next http://localhost:4221/echo/blueberry -H "Connection: close"

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0
HTTP/1.1 200 OK
Connection: close
Content-Type: text/plain
Content-Length: 9

* Closing connection
blueberry

Original README


This is a starting point for TypeScript solutions to the "Build Your Own HTTP server" Challenge.

HTTP is the protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server that is capable of serving multiple clients.

Along the way you'll learn about TCP servers, HTTP request syntax, and more.

Note: If you're viewing this repo on GitHub, head over to codecrafters.io to try the challenge.

Passing the first stage

The entry point for your HTTP server implementation is in app/main.ts. Study and uncomment the relevant code, and push your changes to pass the first stage:

git commit -am "pass 1st stage" # any msg
git push origin master

Time to move on to the next stage!

Stage 2 & beyond

Note: This section is for stages 2 and beyond.

  1. Ensure you have bun (1.2) installed locally
  2. Run ./your_program.sh to run your program, which is implemented in app/main.ts.
  3. Commit your changes and run git push origin master to submit your solution to CodeCrafters. Test output will be streamed to your terminal.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •