cmd/strelaysrv: Don't patch the default HTTP client (fixes #4745)
This commit is contained in:
parent
5e041dca9f
commit
a27032f09e
@ -86,6 +86,12 @@ var (
|
|||||||
pprofEnabled bool
|
pprofEnabled bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// httpClient is the HTTP client we use for outbound requests. It has a
|
||||||
|
// timeout and may get further options set during initialization.
|
||||||
|
var httpClient = &http.Client{
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
||||||
|
|
||||||
@ -129,14 +135,14 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if laddr.IP != nil && !laddr.IP.IsUnspecified() {
|
if laddr.IP != nil && !laddr.IP.IsUnspecified() {
|
||||||
|
// We bind to a specific address. Our outgoing HTTP requests should
|
||||||
|
// also come from that address.
|
||||||
laddr.Port = 0
|
laddr.Port = 0
|
||||||
transport, ok := http.DefaultTransport.(*http.Transport)
|
boundDialer := &net.Dialer{LocalAddr: laddr}
|
||||||
if ok {
|
httpClient.Transport = &http.Transport{
|
||||||
transport.Dial = (&net.Dialer{
|
DialContext: boundDialer.DialContext,
|
||||||
Timeout: 30 * time.Second,
|
|
||||||
LocalAddr: laddr,
|
|
||||||
}).Dial
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -27,7 +26,7 @@ func poolHandler(pool string, uri *url.URL, mapping mapping) {
|
|||||||
uriCopy.String(),
|
uriCopy.String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
resp, err := http.Post(pool, "application/json", &b)
|
resp, err := httpClient.Post(pool, "application/json", &b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error joining pool", pool, err)
|
log.Println("Error joining pool", pool, err)
|
||||||
} else if resp.StatusCode == 500 {
|
} else if resp.StatusCode == 500 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user