-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
28 lines (25 loc) · 778 Bytes
/
Copy pathrequest.go
File metadata and controls
28 lines (25 loc) · 778 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
package proxycheck
import (
"fmt"
"net/http"
"net/url"
"time"
)
// ProxyRequest
// Performs an HTTP request through the proxy specified in the proxyUrl
func ProxyRequest(target string, proxyURL *url.URL, timeout time.Duration) ([]byte, error) {
body := make([]byte, 0)
httpClient := http.Client{
Timeout: timeout,
Transport: createProxyTransport(proxyURL, timeout),
}
if resp, err := httpClient.Get(target); err != nil {
return body, fmt.Errorf("can't http get: %v", err)
} else if body, err := readResponse(resp); err != nil {
return body, fmt.Errorf("error read response: %v", err)
} else if resp.StatusCode != http.StatusOK {
return body, fmt.Errorf("http error, status code %d, response %s", resp.StatusCode, body)
} else {
return body, nil
}
}