What is the minimum size in bytes of an HTTP request? I mean the size of the mandatory data that an HTTP request should consist of, such as header's related fields and considering that the body of the request is empty.
2 Answers
26 bytes
for the exceptional case of a 1 byte resource and 1 byte hostname.
GET / HTTP/1.1<CR><LF>
Host:x<CR><LF>
<CR><LF>
You need an initial request line and, if you're using HTTP 1.1, a Host header. Each newline is two bytes (CRLF). Two parts of this minimal GET request are variable: the resource path and the hostname.
A minimum initial request line is GET / HTTP/1.1
which is 16 bytes (including the two invisible CRLF bytes you don't see).
A minimum Host line is Host:x
, that is, a one byte hostname which results in 8 bytes (again two CRLF bytes).
To signify the end of headers, you need another CRLF, so that's another 2 bytes.
16+8+2=26 bytes
for a minimum HTTP request size.
Of course, this increases if you have a longer hostname or longer path to the resource. To take those into account, the minimum HTTP request size is: 24 + length(resource_path) + length(host)
Here's a real world example using netcat from bash (note the resource path and hostname are both longer than the minimum):
nc -c www.example.com 80 <<EOF
GET /index.html HTTP/1.1
Host:www.example.com
EOF
-
-
2@MrMesees that’s an extra 40 bytes (for IPv4), but the full picture is more complex since HTTP can run over TCP/IPv4 or TCP/IPv6. Also, if TLS is used there is additional overhead. There’s also the network layers beneath IP which have their own overheads as well. Apr 20, 2019 at 15:53
The shortest possible HTTP request is a simple GET
method, made by connecting directly to a specific server. The shortest request is:
GET / HTTP/0.9<CR><LF>
which is a total of 16 bytes, including the CR/LF pair at the end of the line.
For HTTP 1.x (1.0 and 1.1), the presence of headers is expected, so to signify the end of the headers you need an empty line. The shortest request is then:
GET / HTTP/1.0<CR><LF>
<CR><LF>
which is a total of 18 bytes.
(Added after comments by Doug; thanks:) For HTTP 1.1, the Host: header is required. See @DougRichardson's answer for the shortest possible HTTP 1.1 request.
-
1The parameter after GET on the initial request line is the request URI, not the hostname. Jul 31, 2014 at 19:50
-
2Also, for HTTP 1.1, the Host header is a required field when using an absolute path for the request URI. See RFC 2616 section 5.1.2, so the example (for HTTP 1.1 at least) of 18 bytes is not valid HTTP 1.1. Jul 31, 2014 at 19:57
-
@DougRichardson: Which is why the first example was specifically
HTTP/0.9
and the second specificallyHTTP/1.0
. And thanks for the correction about the parameter, I'll correct it.– MenachemJul 31, 2014 at 21:26