HTTP/1.1 connections are persistent - a client can send several requests down one connection. Today you loop on a connection, answering request after request instead of closing after one.
Read and answer multiple requests on a single connection until the client stops sending.
Under HTTP/1.1 a connection is persistent by default: opening a fresh TCP connection per request is wasteful, so a client sends several requests down the same one and reads back several responses in order. Your handler must therefore loop, parsing and answering requests until the client is done.
The loop ends when the reader hits end of input — the client closed its side —
which surfaces as an EOF from the parser. Because you always wrote an accurate
Content-Length, each response’s boundary is unambiguous, so the next request
starts cleanly right after the previous body.
r := bufio.NewReader(conn)for {req, err := parseRequest(r)if err == io.EOF { break } // client closed; nothing more to readconn.Write(handle(req).serialize())}