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

Function testFSFSCompress

fs_fs_test.go:427–556  ·  view source on GitHub ↗
(t *testing.T, h RequestHandler, filePath string)

Source from the content-addressed store, hash-verified

425}
426
427func testFSFSCompress(t *testing.T, h RequestHandler, filePath string) {
428 var ctx RequestCtx
429 ctx.Init(&Request{}, nil, nil)
430
431 var resp Response
432
433 // get uncompressed
434 ctx.Request.SetRequestURI(filePath)
435 h(&ctx)
436
437 s := ctx.Response.String()
438 br := bufio.NewReader(bytes.NewBufferString(s))
439 if err := resp.Read(br); err != nil {
440 t.Fatalf("unexpected error: %v", err)
441 }
442 if resp.StatusCode() != StatusOK {
443 t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusOK)
444 }
445
446 ce := resp.Header.ContentEncoding()
447 if len(ce) > 0 {
448 t.Fatalf("unexpected 'Content-Encoding': %q. Expecting \"\"", string(ce))
449 }
450
451 vary := resp.Header.PeekBytes(strVary)
452 if len(vary) > 0 {
453 t.Fatalf("unexpected 'Vary': %q. Expecting \"\"", string(vary))
454 }
455
456 expectedBody := bytes.Clone(resp.Body())
457
458 // should prefer brotli over zstd, gzip and ignore unknown encoding
459 ctx.Request.Reset()
460 ctx.Request.SetRequestURI(filePath)
461 ctx.Request.Header.Set(HeaderAcceptEncoding, "gzip, zstd, br, wompwomp")
462 h(&ctx)
463
464 s = ctx.Response.String()
465 br = bufio.NewReader(bytes.NewBufferString(s))
466 if err := resp.Read(br); err != nil {
467 t.Fatalf("unexpected error: %v. filePath=%q", err, filePath)
468 }
469 if resp.StatusCode() != StatusOK {
470 t.Fatalf("unexpected status code: %d. Expecting %d. filePath=%q", resp.StatusCode(), StatusOK, filePath)
471 }
472
473 ce = resp.Header.ContentEncoding()
474 if string(ce) != "br" {
475 t.Fatalf("unexpected 'Content-Encoding' %q. Expecting %q. filePath=%q", string(ce), "br", filePath)
476 }
477
478 vary = resp.Header.PeekBytes(strVary)
479 if !bytes.Equal(vary, strAcceptEncoding) {
480 t.Fatalf("unexpected 'Vary': %q. Expecting %q", string(vary), HeaderAcceptEncoding)
481 }
482
483 body, err := resp.BodyUnbrotli()
484 if err != nil {

Calls 14

InitMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
BodyUnbrotliMethod · 0.95
BodyUnzstdMethod · 0.95
BodyGunzipMethod · 0.95
NewReaderMethod · 0.80
ResetMethod · 0.65
SetRequestURIMethod · 0.45
StringMethod · 0.45
ContentEncodingMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…