fail on incomplete staging

This commit is contained in:
Patricio Whittingslow
2026-07-26 11:35:32 -03:00
parent 69640a6235
commit 229acd3e68
5 changed files with 42 additions and 32 deletions
+8 -3
View File
@@ -290,7 +290,7 @@ func TestExchangeReadBody(t *testing.T) {
// SetHeader must budget every byte it writes: colon, CRLF, and the CRLF that
// FlushHeader appends after the last field. Buffers that fit all but the last
// byte must be refused, never overrun.
func TestExchangeSetHeaderExactFit(t *testing.T) {
func TestExchangeStageOKAndFail(t *testing.T) {
const key, value = "K", "V"
const field = len(key) + len(value) + len(":\r\n")
for _, bufLen := range []int{field + 2, field + 1, field} {
@@ -301,13 +301,18 @@ func TestExchangeSetHeaderExactFit(t *testing.T) {
t.Fatal("fresh exchange failed to acquire connection")
}
set := exch.StageHeader(key, value)
exch.WriteHeader(200)
n, err := exch.FlushHeader()
want := "HTTP/1.1 200 OK\r\n"
if set {
want += key + ":" + value + "\r\n"
want += "\r\n"
} else {
if err != lneto.ErrBufferFull || n != 0 {
t.Fatal("expected buffer full and no data written:", err, n)
}
want = ""
}
want += "\r\n"
if got := conn.ViewWritten(); got != want {
t.Errorf("buffer %d: want %q, got %q", bufLen, want, got)
}