forked from TheHackerDev/race-the-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
29 lines (24 loc) · 786 Bytes
/
helpers.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
package main
import (
"bytes"
"io/ioutil"
"net/http"
)
// Function SetDefaults sets the default options, if not present in the configuration file.
// Redirects and verbose are both false, as the default value of a boolean.
func SetDefaults(config *Configuration) {
// Count
if config.Count == 0 {
// Set to default value of 100
config.Count = 100
}
}
// Function ReadResponseBody is a helper function to read the content from a response's body and refill the body with another io.ReadCloser, so that it can be read again.
func ReadResponseBody(resp *http.Response) (content []byte, err error) {
// Get the content
content, err = ioutil.ReadAll(resp.Body)
// Reset the response body
rCloser := ioutil.NopCloser(bytes.NewBuffer(content))
resp.Body = rCloser
return
}