Skip to content

Commit 3918cf3

Browse files
authored
Merge pull request #64 from lutfuahmet/main
HTTP Timeout
2 parents f78c958 + 92b5233 commit 3918cf3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

handlers/proxy.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"net/url"
99
"os"
1010
"regexp"
11+
"strconv"
1112
"strings"
13+
"time"
1214

1315
"ladder/pkg/ruleset"
1416

@@ -21,13 +23,17 @@ var (
2123
ForwardedFor = getenv("X_FORWARDED_FOR", "66.249.66.1")
2224
rulesSet = ruleset.NewRulesetFromEnv()
2325
allowedDomains = []string{}
26+
defaultTimeout = 15 // in seconds
2427
)
2528

2629
func init() {
2730
allowedDomains = strings.Split(os.Getenv("ALLOWED_DOMAINS"), ",")
2831
if os.Getenv("ALLOWED_DOMAINS_RULESET") == "true" {
2932
allowedDomains = append(allowedDomains, rulesSet.Domains()...)
3033
}
34+
if timeoutStr := os.Getenv("HTTP_TIMEOUT"); timeoutStr != "" {
35+
defaultTimeout, _ = strconv.Atoi(timeoutStr)
36+
}
3137
}
3238

3339
// extracts a URL from the request ctx. If the URL in the request
@@ -181,7 +187,9 @@ func fetchSite(urlpath string, queries map[string]string) (string, *http.Request
181187
}
182188

183189
// Fetch the site
184-
client := &http.Client{}
190+
client := &http.Client{
191+
Timeout: time.Second * time.Duration(defaultTimeout),
192+
}
185193
req, _ := http.NewRequest("GET", url, nil)
186194

187195
if rule.Headers.UserAgent != "" {

0 commit comments

Comments
 (0)