-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.go
More file actions
33 lines (29 loc) · 670 Bytes
/
util.go
File metadata and controls
33 lines (29 loc) · 670 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
package http
import (
"bytes"
"io/ioutil"
"net/http"
)
func GetBodyBytes(r *http.Request) []byte {
if r.Body == nil {
return make([]byte, 0)
}
requestBytes, _ := ioutil.ReadAll(r.Body)
r.Body = ioutil.NopCloser(bytes.NewBuffer(requestBytes))
return requestBytes
}
func GetResponseBodyBytes(r *http.Response) []byte {
if r.Body == nil {
return make([]byte, 0)
}
requestBytes, _ := ioutil.ReadAll(r.Body)
r.Body = ioutil.NopCloser(bytes.NewBuffer(requestBytes))
return requestBytes
}
func CopyHeader(source http.Header, target http.Header) {
for header, values := range source {
for _, value := range values {
target.Set(header, value)
}
}
}