-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgovcr.go
50 lines (41 loc) · 1.24 KB
/
govcr.go
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
43
44
45
46
47
48
49
50
package govcr
import "net/http"
// NewVCR creates a new VCR.
func NewVCR(settings ...Setting) *ControlPanel {
var vcrSettings VCRSettings
for _, option := range settings {
option(&vcrSettings)
}
// use a default client if none provided
if vcrSettings.client == nil {
vcrSettings.client = http.DefaultClient
}
// use a default vcrTransport if none provided
if vcrSettings.client.Transport == nil {
vcrSettings.client.Transport = http.DefaultTransport
}
// use a default RequestMatcher if none provided
if vcrSettings.requestMatcher == nil {
vcrSettings.requestMatcher = NewStrictRequestMatcher()
}
// create VCR's HTTP client
vcrClient := &http.Client{
Transport: &vcrTransport{
pcb: &PrintedCircuitBoard{
requestMatcher: vcrSettings.requestMatcher,
trackRecordingMutators: vcrSettings.trackRecordingMutators,
trackReplayingMutators: vcrSettings.trackReplayingMutators,
},
cassette: vcrSettings.cassette,
transport: vcrSettings.client.Transport,
},
// copy the attributes of the original http.Client
CheckRedirect: vcrSettings.client.CheckRedirect,
Jar: vcrSettings.client.Jar,
Timeout: vcrSettings.client.Timeout,
}
// return
return &ControlPanel{
client: vcrClient,
}
}