-
Notifications
You must be signed in to change notification settings - Fork 9
/
request.go
33 lines (28 loc) · 690 Bytes
/
request.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
package vcr
import (
"bytes"
"io/ioutil"
"net/http"
)
type vcrRequest struct {
// Header is intentionally not included and is not used for episode matching
Method string
URL string
Body []byte
}
func newVCRRequest(request *http.Request, filterMap map[string]string) *vcrRequest {
var body []byte
if request.Body != nil {
body, _ = ioutil.ReadAll(request.Body)
request.Body.Close()
request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
for original, replacement := range filterMap {
body = bytes.Replace(body, []byte(original), []byte(replacement), -1)
}
}
return &vcrRequest{
Method: request.Method,
URL: request.URL.String(),
Body: body,
}
}