Skip to content

Commit 3b2b8ff

Browse files
committed
mitm: add response inspection to example
1 parent 83a58b0 commit 3b2b8ff

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

example_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import (
77
"testing"
88
)
99

10+
type codeRecorder struct {
11+
http.ResponseWriter
12+
13+
code int
14+
}
15+
16+
func (w *codeRecorder) WriteHeader(code int) {
17+
w.ResponseWriter.WriteHeader(code)
18+
w.code = code
19+
}
20+
1021
func ExampleProxy(t *testing.T) {
1122
ca, err := loadCA()
1223
if err != nil {
@@ -17,8 +28,10 @@ func ExampleProxy(t *testing.T) {
1728
CA: &ca,
1829
Wrap: func(upstream http.Handler) http.Handler {
1930
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
31+
cr := &codeRecorder{ResponseWriter: w}
2032
log.Println("Got Content-Type:", r.Header.Get("Content-Type"))
21-
upstream.ServeHTTP(w, r)
33+
upstream.ServeHTTP(cr, r)
34+
log.Println("Got Status:", cr.code)
2235
})
2336
},
2437
}

0 commit comments

Comments
 (0)