-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (35 loc) · 840 Bytes
/
example_test.go
File metadata and controls
42 lines (35 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package mitm
import (
"crypto/tls"
"log"
"net/http"
"testing"
)
type codeRecorder struct {
http.ResponseWriter
code int
}
func (w *codeRecorder) WriteHeader(code int) {
w.ResponseWriter.WriteHeader(code)
w.code = code
}
func ExampleProxy(t *testing.T) {
ca, err := loadCA()
if err != nil {
log.Fatal(err)
}
p := &Proxy{
CA: &ca,
Wrap: func(upstream http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cr := &codeRecorder{ResponseWriter: w}
log.Println("Got Content-Type:", r.Header.Get("Content-Type"))
upstream.ServeHTTP(cr, r)
log.Println("Got Status:", cr.code)
})
},
}
listenAndServe(p)
}
func loadCA() (cert tls.Certificate, err error) { panic("example only") }
func listenAndServe(_ http.Handler) { panic("example only") }