forked from seborama/govcr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample4.go
38 lines (32 loc) · 982 Bytes
/
example4.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
package main
import (
"fmt"
"net/http"
"time"
"github.com/seborama/govcr"
)
const example4CassetteName = "MyCassette4"
// Example4 is an example use of govcr.
// The request contains a customer header 'X-Custom-My-Date' which varies with every request.
// This example shows how to exclude a particular header from the request to facilitate
// matching a previous recording.
// Without the RequestFilters, the headers would not match and hence the playback would not
// happen!
func Example4() {
vcr := govcr.NewVCR(example4CassetteName,
&govcr.VCRConfig{
RequestFilters: govcr.RequestFilters{
govcr.RequestDeleteHeaderKeys("X-Custom-My-Date"),
},
Logging: true,
})
// create a request with our custom header
req, err := http.NewRequest("POST", "http://www.example.com/foo", nil)
if err != nil {
fmt.Println(err)
}
req.Header.Add("X-Custom-My-Date", time.Now().String())
// run the request
vcr.Client.Do(req)
fmt.Printf("%+v\n", vcr.Stats())
}