-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Description
There is currently no way to test 1XX responses with the httptest package.
Support for 1XX responses has been added to the built-in HTTP server and reverse proxy in Go 1.19 (#42597, #53164).
I propose to add support for inspecting 1XX responses with the test package by integrating the httptrace package with it (as we've done for the reverse proxy).
Regarding the API, I suggest implementing the same API as when using the non-test client:
func Test1xx(t *testing.T) {
trace := &httptrace.ClientTrace{
Got100Continue: func() {
// do something
},
Got1xxResponse: func(code int, header textproto.MIMEHeader) error {
// do something
return nil
},
}
r, _ := http.NewRequest("GET", "http://example.com", nil)
rw := httptest.NewRecorder()
rw.ClientTrace = trace
func(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Link", "</image.png>; rel=preload; as=image")
rw.WriteHeader(http.StatusEarlyHints)
// ...
}(rw, r)
// ...
}
Proposal implementation: #56151
mitar and Acconut
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Incoming