mirror of
https://github.com/soypat/lneto.git
synced 2026-08-24 08:29:08 +00:00
run go fix
This commit is contained in:
@@ -1012,11 +1012,12 @@ func TestHandleBrowserSizedRequest(t *testing.T) {
|
|||||||
// connection go away. Either bound may be the one it ran into, and both are
|
// connection go away. Either bound may be the one it ran into, and both are
|
||||||
// reported to the caller.
|
// reported to the caller.
|
||||||
func TestHandleRequestTooLargeAnswers431(t *testing.T) {
|
func TestHandleRequestTooLargeAnswers431(t *testing.T) {
|
||||||
request := "GET /echo HTTP/1.1\r\nHost: lneto.test\r\n"
|
var request strings.Builder
|
||||||
for i := 0; i < 512; i++ {
|
request.WriteString("GET /echo HTTP/1.1\r\nHost: lneto.test\r\n")
|
||||||
request += "H" + strconv.Itoa(i) + ":v\r\n"
|
for i := range 512 {
|
||||||
|
request.WriteString("H" + strconv.Itoa(i) + ":v\r\n")
|
||||||
}
|
}
|
||||||
request += "\r\n"
|
request.WriteString("\r\n")
|
||||||
|
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
name string
|
name string
|
||||||
@@ -1046,7 +1047,7 @@ func TestHandleRequestTooLargeAnswers431(t *testing.T) {
|
|||||||
var sm MuxSlice
|
var sm MuxSlice
|
||||||
sm.Reset(1)
|
sm.Reset(1)
|
||||||
sm.Handle("GET /echo", func(exch *Exchange) { served = true })
|
sm.Handle("GET /echo", func(exch *Exchange) { served = true })
|
||||||
conn := newConn(request)
|
conn := newConn(request.String())
|
||||||
conn.Hangup()
|
conn.Hangup()
|
||||||
exch := newExchange(t, conn, test.cfg)
|
exch := newExchange(t, conn, test.cfg)
|
||||||
err := Handle(exch, &sm, nopBackoff)
|
err := Handle(exch, &sm, nopBackoff)
|
||||||
@@ -1065,8 +1066,8 @@ func TestHandleRequestTooLargeAnswers431(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func firstLine(s string) string {
|
func firstLine(s string) string {
|
||||||
if i := strings.Index(s, "\r\n"); i >= 0 {
|
if before, _, ok := strings.Cut(s, "\r\n"); ok {
|
||||||
return s[:i]
|
return before
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -609,15 +609,16 @@ func TestHeader_SetIntNoAlloc(t *testing.T) {
|
|||||||
// exceeds.
|
// exceeds.
|
||||||
func TestHeader_FieldTableSizedFromBuffer(t *testing.T) {
|
func TestHeader_FieldTableSizedFromBuffer(t *testing.T) {
|
||||||
const wantVal = "the-canary-value"
|
const wantVal = "the-canary-value"
|
||||||
raw := "GET / HTTP/1.1\r\nHost: lneto.test\r\n"
|
var raw strings.Builder
|
||||||
for i := 0; i < 40; i++ {
|
raw.WriteString("GET / HTTP/1.1\r\nHost: lneto.test\r\n")
|
||||||
raw += "X-Field-" + strconv.Itoa(i) + ": value-of-a-realistic-length-here\r\n"
|
for i := range 40 {
|
||||||
|
raw.WriteString("X-Field-" + strconv.Itoa(i) + ": value-of-a-realistic-length-here\r\n")
|
||||||
}
|
}
|
||||||
raw += "X-Canary: " + wantVal + "\r\n\r\n"
|
raw.WriteString("X-Canary: " + wantVal + "\r\n\r\n")
|
||||||
|
|
||||||
var h Header
|
var h Header
|
||||||
h.Reset(make([]byte, 0, 8192), numHeaderCapacity) // Room for the block with plenty to spare.
|
h.Reset(make([]byte, 0, 8192), numHeaderCapacity) // Room for the block with plenty to spare.
|
||||||
err := h.ParseBytes(false, []byte(raw))
|
err := h.ParseBytes(false, []byte(raw.String()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("parsing a 42 field request into an 8kB buffer: %s", err)
|
t.Fatalf("parsing a 42 field request into an 8kB buffer: %s", err)
|
||||||
}
|
}
|
||||||
@@ -629,15 +630,16 @@ func TestHeader_FieldTableSizedFromBuffer(t *testing.T) {
|
|||||||
// A buffer too small for the fields it is handed must be refused with an error
|
// A buffer too small for the fields it is handed must be refused with an error
|
||||||
// the caller can act on, so a server answers 431 instead of dropping the peer.
|
// the caller can act on, so a server answers 431 instead of dropping the peer.
|
||||||
func TestHeader_FieldTableFullIsReported(t *testing.T) {
|
func TestHeader_FieldTableFullIsReported(t *testing.T) {
|
||||||
raw := "GET / HTTP/1.1\r\n"
|
var raw strings.Builder
|
||||||
for i := 0; i < 64; i++ {
|
raw.WriteString("GET / HTTP/1.1\r\n")
|
||||||
raw += "H" + strconv.Itoa(i) + ":v\r\n" // As short as a field gets.
|
for i := range 64 {
|
||||||
|
raw.WriteString("H" + strconv.Itoa(i) + ":v\r\n") // As short as a field gets.
|
||||||
}
|
}
|
||||||
raw += "\r\n"
|
raw.WriteString("\r\n")
|
||||||
var h Header
|
var h Header
|
||||||
h.Reset(make([]byte, 0, 512), numHeaderCapacity)
|
h.Reset(make([]byte, 0, 512), numHeaderCapacity)
|
||||||
h.ConfigBufferGrowth(false)
|
h.ConfigBufferGrowth(false)
|
||||||
err := h.ParseBytes(false, []byte(raw))
|
err := h.ParseBytes(false, []byte(raw.String()))
|
||||||
if !errors.Is(err, ErrHeaderTooMany) {
|
if !errors.Is(err, ErrHeaderTooMany) {
|
||||||
t.Fatalf("want ErrHeaderFieldsTooLarge, got %v", err)
|
t.Fatalf("want ErrHeaderFieldsTooLarge, got %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user