(t *testing.T, opts *testOptions)
| 575 | testEarlyHints(t, &testOptions{workerScript: "early-hints.php"}) |
| 576 | } |
| 577 | func testEarlyHints(t *testing.T, opts *testOptions) { |
| 578 | runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { |
| 579 | var earlyHintReceived bool |
| 580 | trace := &httptrace.ClientTrace{ |
| 581 | Got1xxResponse: func(code int, header textproto.MIMEHeader) error { |
| 582 | switch code { |
| 583 | case http.StatusEarlyHints: |
| 584 | assert.Equal(t, "</style.css>; rel=preload; as=style", header.Get("Link")) |
| 585 | assert.Equal(t, strconv.Itoa(i), header.Get("Request")) |
| 586 | |
| 587 | earlyHintReceived = true |
| 588 | } |
| 589 | |
| 590 | return nil |
| 591 | }, |
| 592 | } |
| 593 | req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/early-hints.php?i=%d", i), nil) |
| 594 | w := NewRecorder() |
| 595 | w.ClientTrace = trace |
| 596 | handler(w, req) |
| 597 | |
| 598 | assert.Equal(t, strconv.Itoa(i), w.Header().Get("Request")) |
| 599 | assert.Equal(t, "", w.Header().Get("Link")) |
| 600 | |
| 601 | assert.True(t, earlyHintReceived) |
| 602 | }, opts) |
| 603 | } |
| 604 | |
| 605 | type streamResponseRecorder struct { |
| 606 | *httptest.ResponseRecorder |
no test coverage detected