MCPcopy Index your code
hub / github.com/php/frankenphp / testEarlyHints

Function testEarlyHints

frankenphp_test.go:577–603  ·  view source on GitHub ↗
(t *testing.T, opts *testOptions)

Source from the content-addressed store, hash-verified

575 testEarlyHints(t, &testOptions{workerScript: "early-hints.php"})
576}
577func 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
605type streamResponseRecorder struct {
606 *httptest.ResponseRecorder

Callers 2

TestEarlyHints_moduleFunction · 0.85
TestEarlyHints_workerFunction · 0.85

Calls 4

runTestFunction · 0.85
NewRecorderFunction · 0.85
GetMethod · 0.80
HeaderMethod · 0.80

Tested by

no test coverage detected