fix: User-Agent on all direct HTTP calls + domain_collision, bump 5.0.75

This commit is contained in:
“Naeel”
2026-07-01 16:29:04 +04:00
parent a8d3be1849
commit cdaa78ecee
3 changed files with 15 additions and 4 deletions
+13 -3
View File
@@ -34,6 +34,10 @@ type ctxKeyLogLevelType struct{}
var ctxKeyLogLevel = ctxKeyLogLevelType{}
// userAgent — браузерный, чтобы пройти DDoS-Guard.
// Go-http-client по умолчанию блокируется фильтром ddos-guard.
const userAgent = "Mozilla/5.0"
// CtxWithLogLevel возвращает ctx с переопределённым уровнем логирования.
func CtxWithLogLevel(ctx context.Context, level string) context.Context {
return context.WithValue(ctx, ctxKeyLogLevel, level)
@@ -513,6 +517,7 @@ func (c *UniversalClient) FindInstanceByDisplayName(ctx context.Context, service
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
if c.ApiToken != "" {
req.Header.Set("Authorization", "Bearer "+c.ApiToken)
}
@@ -587,6 +592,7 @@ func (c *UniversalClient) GetInstanceState(ctx context.Context, instanceUid stri
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
if c.ApiToken != "" {
req.Header.Set("Authorization", "Bearer "+c.ApiToken)
}
@@ -633,6 +639,7 @@ func (c *UniversalClient) GetInstanceStateRaw(ctx context.Context, instanceUid s
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
if c.ApiToken != "" {
req.Header.Set("Authorization", "Bearer "+c.ApiToken)
}
@@ -805,7 +812,6 @@ func (c *UniversalClient) waitForInstanceIdle(ctx context.Context, instanceUid s
func (c *UniversalClient) doRequest(ctx context.Context, method, path string, payload interface{}) ([]byte, http.Header, error) {
// User-Agent: браузерный, чтобы пройти DDoS-Guard (см. docs/ops/API_TOKENS.md).
// Go-http-client по умолчанию блокируется фильтром ddos-guard.
const userAgent = "Mozilla/5.0"
const maxRetries = 3
baseDelay := 2 * time.Second
@@ -865,9 +871,13 @@ func (c *UniversalClient) doRequest(ctx context.Context, method, path string, pa
fmt.Fprintf(os.Stderr, "\n>>> REQ %s %s\n%s\n", method, path, dump)
}
// DEBUG
// DEBUG в файл
if os.Getenv("NUBES_DEBUG_HTTP") == "1" {
fmt.Fprintf(os.Stderr, ">>> %s %s\n", method, req.URL.String())
f, _ := os.OpenFile("/tmp/nubes_debug.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if f != nil {
fmt.Fprintf(f, ">>> %s %s\n", method, req.URL.String())
f.Close()
}
}
resp, err := c.HttpClient.Do(req)
if err != nil {
@@ -96,6 +96,7 @@ func collectDomainOwners(ctx context.Context, client *core.UniversalClient, allo
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "Mozilla/5.0")
if client.ApiToken != "" {
req.Header.Set("Authorization", "Bearer "+client.ApiToken)
}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
var (
version string = "5.0.74"
version string = "5.0.75"
)
func main() {