Inspect text protocols
Send an HTTP request by hand
Type a complete HTTP/1.1 request through a Telnet client and see the protocol message carried inside TCP.
8 minute lesson
Create http-server.mjs so the exercise has a local HTTP server:
import http from 'node:http'
http.createServer((request, response) => {
response.end('Hello from HTTP\n')
}).listen(8000, '127.0.0.1')
Run it with node http-server.mjs. Then connect its port with the Telnet client:
telnet 127.0.0.1 8000
Type these lines, then press Enter once more to send the empty line that ends the headers:
GET / HTTP/1.1
Host: localhost
Connection: close
The server responds with a status line, headers, an empty line, and usually a body. Connection: close makes the end easy to observe because the server closes the TCP connection after the response.
You just used a Telnet client to speak HTTP. The request grammar came from HTTP, while TCP transported the bytes and the Telnet program provided the interactive connection.
Connect to a local HTTP server or a host you control, then type a complete request followed by a blank line:
GET / HTTP/1.1
Host: localhost
Connection: close
Read the status line, headers, blank line, and body. Telnet does not understand HTTP here. It only carries the bytes you type. Repeat with curl -v and compare the exact request and response boundaries.
Lesson completed