Skip to content

Commit

Permalink
Merge pull request #64 from lutfuahmet/main
Browse files Browse the repository at this point in the history
HTTP Timeout
  • Loading branch information
mms-gianni authored Dec 7, 2023
2 parents f78c958 + 92b5233 commit 3918cf3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion handlers/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"net/url"
"os"
"regexp"
"strconv"
"strings"
"time"

"ladder/pkg/ruleset"

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

func init() {
allowedDomains = strings.Split(os.Getenv("ALLOWED_DOMAINS"), ",")
if os.Getenv("ALLOWED_DOMAINS_RULESET") == "true" {
allowedDomains = append(allowedDomains, rulesSet.Domains()...)
}
if timeoutStr := os.Getenv("HTTP_TIMEOUT"); timeoutStr != "" {
defaultTimeout, _ = strconv.Atoi(timeoutStr)
}
}

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

// Fetch the site
client := &http.Client{}
client := &http.Client{
Timeout: time.Second * time.Duration(defaultTimeout),
}
req, _ := http.NewRequest("GET", url, nil)

if rule.Headers.UserAgent != "" {
Expand Down

0 comments on commit 3918cf3

Please sign in to comment.