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.
Ideally, an HTTP request should not go beyond 1 packet. The most widely used networks limit packets to approximately 1500 bytes, so if you can constrain each request to fewer than 1500 bytes, you can reduce the overhead of the request stream.
The default value of the HTTP and HTTPS connector maximum post size is 2MB. However you can adjust the value as per your requirement. The below command to set the connector to accept maximum 100,000 bytes. If the http request POST size exceeds the 100,000 bytes then connector return HTTP/1.1 400 Bad Request.
The HTTP protocol does not specify a limit. The POST method allows sending far more data than the GET method, which is limited by the URL length - about 2KB.
The default HTTP Request Header value is 8190 bytes.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With