10/100

Building an HTTP Server

Jonathan Leeming

Building an HTTP Server


What is HTTP?


Hyper

Text

Transfer

Protocol


Clarification


Evolution of HTTP – MDN


What does HTTP look like?


1
2
3
4
5
6
GET /greet HTTP/1.0
Host: example.com
Content-Type: application/json
Content-Length: 19

{ "name": "world" }

1
2
3
4
5
6
GET /greet HTTP/1.0
Host: example.com
Content-Type: application/json
Content-Length: 19

{ "name": "world" }

1
2
3
4
5
6
GET /greet HTTP/1.0
Host: example.com
Content-Type: application/json
Content-Length: 19

{ "name": "world" }

1
2
3
4
5
6
GET /greet HTTP/1.0
Host: example.com
Content-Type: application/json
Content-Length: 19

{ "name": "world" }

1
2
3
4
5
6
HTTP/1.0 200 OK
Server: my-http
Date: Mon, 11 Sep 2023 09:48:19 GMT
Content-Length: 13

Hello, world!

1
2
3
4
5
6
HTTP/1.0 200 OK
Server: my-http
Date: Mon, 11 Sep 2023 09:48:19 GMT
Content-Length: 13

Hello, world!

1
2
3
4
5
6
HTTP/1.0 200 OK
Server: my-http
Date: Mon, 11 Sep 2023 09:48:19 GMT
Content-Length: 13

Hello, world!

1
2
3
4
5
6
HTTP/1.0 200 OK
Server: my-http
Date: Mon, 11 Sep 2023 09:48:19 GMT
Content-Length: 13

Hello, world!

  1. Download the template
  2. Echo server
  3. Handle control data
  4. Handle headers
  5. Handle body
  6. Send a static response
  7. Generate a response dynamically
  8. Return error responses
  9. Handle requests to different URLs