(t *testing.T, h RequestHandler, filePath string)
| 425 | } |
| 426 | |
| 427 | func 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 { |
no test coverage detected
searching dependent graphs…