MCPcopy
hub / github.com/valyala/fasthttp / TestServerErrSmallBuffer

Function TestServerErrSmallBuffer

server_test.go:461–507  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

459}
460
461func TestServerErrSmallBuffer(t *testing.T) {
462 t.Parallel()
463
464 s := &Server{
465 Handler: func(ctx *RequestCtx) {
466 ctx.WriteString("shouldn't be never called") //nolint:errcheck
467 },
468 ReadBufferSize: 20,
469 }
470
471 rw := &readWriter{}
472 rw.r.WriteString("GET / HTTP/1.1\r\nHost: aabb.com\r\nVERY-long-Header: sdfdfsd dsf dsaf dsf df fsd\r\n\r\n")
473
474 ch := make(chan error)
475 go func() {
476 ch <- s.ServeConn(rw)
477 }()
478
479 var serverErr error
480 select {
481 case serverErr = <-ch:
482 case <-time.After(200 * time.Millisecond):
483 t.Fatal("timeout")
484 }
485
486 if serverErr == nil {
487 t.Fatal("expected error")
488 }
489
490 br := bufio.NewReader(&rw.w)
491 var resp Response
492 if err := resp.Read(br); err != nil {
493 t.Fatalf("unexpected error: %v", err)
494 }
495 statusCode := resp.StatusCode()
496 if statusCode != StatusRequestHeaderFieldsTooLarge {
497 t.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusRequestHeaderFieldsTooLarge)
498 }
499 if !resp.ConnectionClose() {
500 t.Fatal("missing 'Connection: close' response header")
501 }
502
503 expectedErr := ErrSmallReadBuffer.Error()
504 if !strings.Contains(serverErr.Error(), expectedErr) {
505 t.Fatalf("unexpected log output: %v. Expecting %q", serverErr, expectedErr)
506 }
507}
508
509func TestRequestCtxIsTLS(t *testing.T) {
510 t.Parallel()

Callers

nothing calls this directly

Calls 7

ServeConnMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.95
ConnectionCloseMethod · 0.95
NewReaderMethod · 0.80
WriteStringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…