Older servers sometimes wrap a long header value across lines, continuing it with leading whitespace. A robust client still has to read those, so today you fold a continuation line back onto its header.
Fold a continuation line - one starting with a space or tab - onto the previous header value.
HTTP/1.1’s obsolete line folding let a header value span several lines by
starting each continuation with a space or tab. It is deprecated for senders,
but a client that talks to real servers still has to read it - so when a header
line begins with whitespace, it is not a new header, it is more of the previous
one. X-Trace: alpha followed by a line beta folds into alpha beta.
The rule is: on a line starting with SP or HTAB, strip the leading whitespace
and append it to the previous header’s value with a single joining space; on any
other line, parse a fresh Name: Value. This is a small branch inside the header
loop you already have, and it is the last wrinkle in reading a header block before
you handle the trickier body framings.
// if a header line starts with SP or HTAB, it is a CONTINUATION// of the previous header: strip its leading whitespace and append// it to the previous value, joined by a single space.// otherwise, parse it as a new "Name: Value" line.