add flaresolverr timeout option
All checks were successful
docker / docker (push) Successful in 27m21s
All checks were successful
docker / docker (push) Successful in 27m21s
Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
parent
99cf009aac
commit
843f23f518
5
main.go
5
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"anonymousoverflow/env"
|
"anonymousoverflow/env"
|
||||||
"anonymousoverflow/src/middleware"
|
"anonymousoverflow/src/middleware"
|
||||||
"anonymousoverflow/src/routes"
|
"anonymousoverflow/src/routes"
|
||||||
|
"anonymousoverflow/src/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -14,8 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
env.RunChecks()
|
env.RunChecks()
|
||||||
|
utils.ReqSetup()
|
||||||
|
|
||||||
host := os.Getenv("HOST")
|
host := os.Getenv("HOST")
|
||||||
if host == "" {
|
if host == "" {
|
||||||
@ -29,7 +30,6 @@ func main() {
|
|||||||
|
|
||||||
if os.Getenv("DEV") != "true" {
|
if os.Getenv("DEV") != "true" {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
fmt.Printf("Listening on %s:%s\n", host, port)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
@ -92,5 +92,6 @@ func main() {
|
|||||||
sePingCheck := checks.NewPingCheck("https://stackexchange.com", "GET", 5000, nil, nil)
|
sePingCheck := checks.NewPingCheck("https://stackexchange.com", "GET", 5000, nil, nil)
|
||||||
healthcheck.New(r, config.DefaultConfig(), []checks.Check{soPingCheck, sePingCheck})
|
healthcheck.New(r, config.DefaultConfig(), []checks.Check{soPingCheck, sePingCheck})
|
||||||
|
|
||||||
|
fmt.Printf("Starting the web server on %s:%s\n", host, port)
|
||||||
r.Run(fmt.Sprintf("%s:%s", host, port))
|
r.Run(fmt.Sprintf("%s:%s", host, port))
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
@ -79,17 +80,20 @@ func (s *Solution) HttpCookies() []*http.Cookie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.3"
|
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.3"
|
||||||
|
const DEFAULT_TIMEOUT = 120
|
||||||
|
|
||||||
var solution *Solution = nil
|
var (
|
||||||
|
solution *Solution = nil
|
||||||
|
fs_url string = ""
|
||||||
|
fs_timeout int = DEFAULT_TIMEOUT
|
||||||
|
)
|
||||||
|
|
||||||
func Solve(target string) error {
|
func Solve(target string) error {
|
||||||
fsurl := os.Getenv("FLARESOLVER")
|
if fs_url == "" {
|
||||||
|
|
||||||
if fsurl == "" {
|
|
||||||
return fmt.Errorf("flaresolver is not configured")
|
return fmt.Errorf("flaresolver is not configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
fsurl, _ = url.JoinPath(fsurl, "/v1")
|
url, _ := url.JoinPath(fs_url, "/v1")
|
||||||
response := Response{}
|
response := Response{}
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
|
|
||||||
@ -97,10 +101,10 @@ func Solve(target string) error {
|
|||||||
SetBody(Request{
|
SetBody(Request{
|
||||||
Cmd: "request.get",
|
Cmd: "request.get",
|
||||||
Url: target,
|
Url: target,
|
||||||
MaxTimeout: 40_000,
|
MaxTimeout: fs_timeout * 100,
|
||||||
OnlyCookies: true,
|
OnlyCookies: true,
|
||||||
}).
|
}).
|
||||||
Post(fsurl)
|
Post(url)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("request failed: %s", err.Error())
|
return fmt.Errorf("request failed: %s", err.Error())
|
||||||
@ -148,3 +152,23 @@ func GET(target string, no_retry ...bool) (*resty.Response, error) {
|
|||||||
|
|
||||||
return nil, fmt.Errorf("solution did not work")
|
return nil, fmt.Errorf("solution did not work")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReqSetup() {
|
||||||
|
fs_url = os.Getenv("FLARESOLVER")
|
||||||
|
timeout := os.Getenv("TIMEOUT")
|
||||||
|
|
||||||
|
if timeout == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if to, err := strconv.Atoi(timeout); err != nil {
|
||||||
|
fmt.Printf("failed to parse timeout: %s\n", err.Error())
|
||||||
|
} else if to <= 0 {
|
||||||
|
fmt.Println("invalid timeout, timeout should be greater than zero")
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("using the default timeout instead (%d secs)\n", DEFAULT_TIMEOUT)
|
||||||
|
fs_timeout = DEFAULT_TIMEOUT
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user