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

Function TestBodyDecodeWithLimitTooLarge

http_test.go:463–525  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

461}
462
463func TestBodyDecodeWithLimitTooLarge(t *testing.T) {
464 t.Parallel()
465
466 body := bytes.Repeat([]byte("a"), 2*1024)
467 maxBodySize := 1024
468
469 testCases := []struct {
470 name string
471 encoding string
472 encode func([]byte) []byte
473 }{
474 {
475 name: "gzip",
476 encoding: "gzip",
477 encode: func(src []byte) []byte {
478 return AppendGzipBytes(nil, src)
479 },
480 },
481 {
482 name: "deflate",
483 encoding: "deflate",
484 encode: func(src []byte) []byte {
485 return AppendDeflateBytes(nil, src)
486 },
487 },
488 {
489 name: "brotli",
490 encoding: "br",
491 encode: func(src []byte) []byte {
492 return AppendBrotliBytes(nil, src)
493 },
494 },
495 {
496 name: "zstd",
497 encoding: "zstd",
498 encode: func(src []byte) []byte {
499 return AppendZstdBytes(nil, src)
500 },
501 },
502 }
503
504 for _, testCase := range testCases {
505 t.Run(testCase.name+"_request_uncompressed", func(t *testing.T) {
506 var req Request
507 req.Header.SetContentEncoding(testCase.encoding)
508 req.SetBodyRaw(testCase.encode(body))
509 _, err := req.BodyUncompressedWithLimit(maxBodySize)
510 if !errors.Is(err, ErrBodyTooLarge) {
511 t.Fatalf("unexpected error: %v", err)
512 }
513 })
514
515 t.Run(testCase.name+"_response_uncompressed", func(t *testing.T) {
516 var resp Response
517 resp.Header.SetContentEncoding(testCase.encoding)
518 resp.SetBodyRaw(testCase.encode(body))
519 _, err := resp.BodyUncompressedWithLimit(maxBodySize)
520 if !errors.Is(err, ErrBodyTooLarge) {

Callers

nothing calls this directly

Calls 9

SetBodyRawMethod · 0.95
SetBodyRawMethod · 0.95
AppendGzipBytesFunction · 0.85
AppendDeflateBytesFunction · 0.85
AppendBrotliBytesFunction · 0.85
AppendZstdBytesFunction · 0.85
SetContentEncodingMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…