Minimum HTTP request request size in bytes

What is the minimum byte size of an HTTP request? I mean the size of the required data that the HTTP request should consist of, for example, the fields associated with the headers, and given that the request body is empty.

+13
html web byte size
source share
2 answers

The shortest possible HTTP request is a simple GET method created by connecting directly to a specific server. Shortest request:

 GET / HTTP/0.9<CR><LF> 

which is a total of 16 bytes, including a CR / LF pair at the end of the line.

For HTTP 1.x (1.0 and 1.1), headers are expected to be present, so to mark the end of the headers you need an empty string. Shortest request:

 GET / HTTP/1.0<CR><LF> <CR><LF> 

which is a total of 18 bytes.

(Added after Doug comments; thanks :) For HTTP 1.1, the Host: header is required. See @DougRichardson's answer for the shortest HTTP 1.1 request.

+8
source

26 bytes

for an exceptional case, a 1-byte resource and a 1-byte hostname.

 GET / HTTP/1.1<CR><LF> Host:x<CR><LF> <CR><LF> 

You need the start line of the request and, if you are using HTTP 1.1, the Host header. Each new line is two bytes (CRLF). The two parts of this minimum GET request are variables: the path to the resource and the host name.

The minimum initial request line is GET / HTTP/1.1 , which is 16 bytes (including two invisible CRLF bytes that you cannot see).

The minimum host string is Host:x , that is, a single-byte host name that gives 8 bytes (again, two CRLF bytes).

To mark the end of the headers, you need another CRLF, so there are 2 more bytes.

16+8+2=26 bytes for the minimum size of an HTTP request.

Of course, this increases if you have a longer host name or a longer path to the resource. To take this into account, the minimum HTTP request size is 24 + length(resource_path) + length(host)

Here is a real bash netcat example (note that the resource path and hostname are longer than the minimum):

 nc -c www.example.com 80 <<EOF GET /index.html HTTP/1.1 Host:www.example.com EOF 
+6
source

All Articles