3 Commits

Author SHA1 Message Date
mms-gianni
3918cf39ac Merge pull request #64 from lutfuahmet/main
HTTP Timeout
2023-12-07 09:37:24 +01:00
ahmetlutfu
92b5233257 overriding default timeout via HTTP_TIMEOUT env variable. 2023-12-06 23:11:58 +03:00
ahmetlutfu
a849603d8b added timeout for http client 2023-12-06 23:07:52 +03:00
3 changed files with 15 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ COPY . .
RUN go mod download
RUN make build
RUN CGO_ENABLED=0 GOOS=linux go build -o ladder cmd/main.go
FROM debian:12-slim as release
@@ -18,4 +18,8 @@ RUN chmod +x /app/ladder
RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/*
#EXPOSE 8080
#ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["sh", "-c", "/app/ladder"]

View File

@@ -3,7 +3,7 @@ services:
ladder:
image: ghcr.io/everywall/ladder:latest
container_name: ladder
build: .
#build: .
#restart: always
#command: sh -c ./ladder
environment:

View File

@@ -8,7 +8,9 @@ import (
"net/url"
"os"
"regexp"
"strconv"
"strings"
"time"
"ladder/pkg/ruleset"
@@ -21,6 +23,7 @@ var (
ForwardedFor = getenv("X_FORWARDED_FOR", "66.249.66.1")
rulesSet = ruleset.NewRulesetFromEnv()
allowedDomains = []string{}
defaultTimeout = 15 // in seconds
)
func init() {
@@ -28,6 +31,9 @@ func init() {
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
@@ -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 != "" {