visit
HTTP is an application layer protocol working on top of TCP/IP and is widely used on the Internet to access websites. It’s a text-based protocol up to version 2
when a binary version was first introduced. Understanding HTTP on a basic level is crucial for both back-end and front-end software engineers. Here’s a short explanation of how HTTP works.
80.87.97.149
What happens when you click a link in a browser? First, the browser requests the DNS to resolve the IP address from a domain name. Second, it establishes a TCP connection to the resolved IP address. Then it sends an HTTP request which is a simple text message terminated by two CRLF
. The browser waits until it gets an HTTP response which is again a text message terminated by two CRLF
.
The first line consists of a method followed by a path and a protocol. The rest are headers, and the majority of them are optional. In fact, some web servers would even allow you to skip the Host
header.
The first line consists of an HTTP protocol followed by a status code and status message. The next lines are headers separated from a body by two CRLF
. The body itself is terminated by another two CRLF
.
$ dig atabakoff.com
;; ANSWER SECTION:
atabakoff.com. 300 IN A 80.87.97.149
Then start telnet and open a connection to the IP address we resolved on port 80
:
$ telnet
telnet> open 80.87.97.149 80
Trying 80.87.97.149...
Connected to 80.87.97.149.
Escape character is '^]'.
Now you can make HTTP requests, let’s just GET
the main page:
GET / HTTP/1.1
Host: atabakoff.com
User-Agent: ziccurat
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Fri, 17 Mar 2023 17:49:08 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: //atabakoff.com/
The response code 301
is because my web server is configured to redirect to the encrypted HTTPS location. Telnet can only be used for bare HTTP, but we can utilize other tools like CURL.
$ curl -L //github.com/yt-dlp/yt-dlp/releases/download/2023.03.04/yt-dlp_linux -o yt-dlp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 27.9M 100 27.9M 0 0 10.0M 0 0:00:02 0:00:02 --:--:-- 11.0M
-L
option is to follow redirects and -o
to specify a file name. By default, curl
doesn’t follow redirects and will silently end. To debug use the -v
option that tells it to be verbose.
$ curl httpbin.org/ip
{
"origin": "217.231.24.43"
}
HTTP is the main application protocol of the Internet, and its understanding can even be helpful on a user level. A form does not work, and you have no idea why? Hit F12
, open the Network
tab, and see that a server returns an error that is never shown to you. Now you have some valuable information to contact support or realize that you only need to wait a minute.