Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 5465f31

Browse files
committed
Use http.Client with Timeout
1 parent c9a8f7a commit 5465f31

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/github.com/stellar/gateway/bridge/app.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,28 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) {
139139

140140
requestHandler := handlers.RequestHandler{}
141141

142-
federationClient := &federation.Client{
143-
HTTP: http.DefaultClient,
144-
StellarTOML: stellartoml.DefaultClient,
142+
httpClientWithTimeout := http.Client{
143+
Timeout: 10 * time.Second,
144+
}
145+
146+
stellartomlClient := stellartoml.Client{
147+
HTTP: &httpClientWithTimeout,
148+
}
149+
150+
federationClient := federation.Client{
151+
HTTP: &httpClientWithTimeout,
152+
StellarTOML: &stellartomlClient,
145153
}
146154

147155
err = g.Provide(
148156
&inject.Object{Value: &requestHandler},
149157
&inject.Object{Value: &config},
150-
&inject.Object{Value: stellartoml.DefaultClient},
151-
&inject.Object{Value: federationClient},
158+
&inject.Object{Value: &stellartomlClient},
159+
&inject.Object{Value: &federationClient},
152160
&inject.Object{Value: &h},
153161
&inject.Object{Value: &ts},
154162
&inject.Object{Value: &paymentListener},
155-
&inject.Object{Value: &http.Client{}},
163+
&inject.Object{Value: &httpClientWithTimeout},
156164
)
157165

158166
if err != nil {

src/github.com/stellar/gateway/compliance/app.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
log "github.com/Sirupsen/logrus"
66
"net/http"
77
"os"
8+
"time"
89

910
"github.com/facebookgo/inject"
1011
"github.com/stellar/gateway/compliance/config"
@@ -62,9 +63,17 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) {
6263

6364
requestHandler := handlers.RequestHandler{}
6465

65-
federationClient := &federation.Client{
66-
HTTP: http.DefaultClient,
67-
StellarTOML: stellartoml.DefaultClient,
66+
httpClientWithTimeout := http.Client{
67+
Timeout: 10 * time.Second,
68+
}
69+
70+
stellartomlClient := stellartoml.Client{
71+
HTTP: &httpClientWithTimeout,
72+
}
73+
74+
federationClient := federation.Client{
75+
HTTP: &httpClientWithTimeout,
76+
StellarTOML: &stellartomlClient,
6877
}
6978

7079
err = g.Provide(
@@ -73,9 +82,9 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) {
7382
&inject.Object{Value: &entityManager},
7483
&inject.Object{Value: &repository},
7584
&inject.Object{Value: &crypto.SignerVerifier{}},
76-
&inject.Object{Value: stellartoml.DefaultClient},
77-
&inject.Object{Value: federationClient},
78-
&inject.Object{Value: &http.Client{}},
85+
&inject.Object{Value: &stellartomlClient},
86+
&inject.Object{Value: &federationClient},
87+
&inject.Object{Value: &httpClientWithTimeout},
7988
&inject.Object{Value: &handlers.NonceGenerator{}},
8089
)
8190

0 commit comments

Comments
 (0)