Net.HTTP.Limits
How much of a peer's message HTTP reads before it refuses or gives up, and how long it waits.
let strict = Limits.headBytes(8192) <> Limits.fields(50)
let l = strict <> Limits.stall(Duration.seconds(10))
Limits is a set of overrides of the defaults. Each function below
returns a value that overrides one limit; empty overrides none, and
<> (combine) joins two, the right side winning wherever both override
the same limit. That join is associative, so settings can be named, reused
and built up in any grouping. values(l) returns every limit with the
overrides applied. A limit can be added without breaking a program that
sets the others.
Each function panics on a limit below 1, or a duration that is not positive: a limit of none would refuse every message, which is a mistake in the program.
| limit | default | what is over it |
|------------------|---------|------------------------------------------|
| headBytes | 16 KiB | a head, refused with 431 |
| fields | 100 | field lines in a head, refused with 431 |
| lineBytes | 8 KiB | a request line, refused with 414 |
| chunkLineBytes | 1 KiB | a chunk-size line with its extensions |
| trailerBytes | 4 KiB | the trailer fields after a chunked body |
| drainBytes | 256 KiB | an unread body, discarded to keep the |
| | | connection open; a longer one closes it |
| headTimeout | 30 s | a whole request head, from its first |
| | | byte, or a TLS handshake and the first |
| | | head from the connection's start |
| stall | 30 s | a read or write blocked without progress |
| idleTimeout | 60 s | a kept-alive connection with no request |
| lingerIdle | 5 s | a read while a connection closes after a |
| | | request it did not read to its end |
| lingerTotal | 30 s | all of that closing |
| connections | 1024 | connections a server holds at once; the |
| | | next waits in the listener's backlog |
Each byte count includes the CRLFs. The chunk-line limit is what keeps a peer from sending a gigabyte of chunk extensions, which no reader looks at. A chunk size also has at most 16 hex digits whatever the limits, since a longer one cannot be a length.
The head timeout is a deadline, not a timer between reads, so a head dripped a byte at a time cannot hold a connection past it. The stall limit is the other kind: a limit on progress. It bounds how long one read or write waits without moving a byte, so a slow but steady body goes on, and a peer that stops sending, or stops reading what it is sent, is cut off. It never counts time in which nothing was being read or written, so a quiet stream whose program has nothing to send is not cut.
Every limit, with a set of overrides applied.
Returns every limit, each l's override or else its default.