v5.0.71: rawQuery (no %2F) + Accept: */* (DDoS-Guard POST fix)

This commit is contained in:
“Naeel”
2026-07-01 15:52:50 +04:00
parent 3f9b02c7f7
commit f2d2b02e45
4 changed files with 156 additions and 13 deletions
+12 -11
View File
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/http"
"net/http/httputil"
"net/url"
"os"
"regexp"
@@ -833,27 +834,21 @@ func (c *UniversalClient) doRequest(ctx context.Context, method, path string, pa
return nil, nil, err
}
// ?endpoint= формат — как генератор (Python) и curl
// ?endpoint= формат — без url.Values.Encode (сохраняет / как /)
endpointPath := path
extraQuery := ""
if idx := strings.Index(path, "?"); idx >= 0 {
endpointPath = path[:idx]
extraQuery = path[idx+1:]
}
q := req.URL.Query()
q.Set("endpoint", endpointPath)
rawQuery := "endpoint=" + endpointPath
if extraQuery != "" {
// Добавляем параметры из path в URL (не в endpoint)
for _, param := range strings.Split(extraQuery, "&") {
kv := strings.SplitN(param, "=", 2)
if len(kv) == 2 {
q.Set(kv[0], kv[1])
}
}
rawQuery += "&" + extraQuery
}
req.URL.RawQuery = q.Encode()
req.URL.RawQuery = rawQuery
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Accept", "*/*")
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
@@ -861,6 +856,12 @@ func (c *UniversalClient) doRequest(ctx context.Context, method, path string, pa
req.Header.Set("Authorization", "Bearer "+c.ApiToken)
}
// DEBUG
if os.Getenv("NUBES_DEBUG_HTTP") == "1" {
dump, _ := httputil.DumpRequestOut(req, body != nil)
fmt.Fprintf(os.Stderr, "\n>>> REQ %s %s\n%s\n", method, path, dump)
}
resp, err := c.HttpClient.Do(req)
if err != nil {
lastErr = err