Files
v2rayA/service/common/httpClient/httpGetUsingSpecificClient.go
T
Zakk ac79c92d6c fix(service): make API error messages say what was rejected and why
Errors that reach the GUI were written for the log: "ResolveURL failed:
invalid parameters", "httpGetUsingSpecificClient: response is nil",
"LocateServerRaw: invalid TYPE", "bad request", "illegal base64 data at
input byte 18". Reword the messages that can reach a user so each names
the input that was rejected (link scheme, missing password, port, server
id, request field), states the expected form for malformed input, drops
Go function names, keeps the %w chain so errors.Is/As still work, and
never echoes passwords, tokens or full share links (hosts only).
Messages the GUI string-matches ("invalid config", "the last request is
being processed") are unchanged.
2026-09-18 02:53:32 +10:00

35 lines
829 B
Go

package httpClient
import (
"errors"
"fmt"
"net/http"
neturl "net/url"
"github.com/v2rayA/v2rayA/conf"
)
func HttpGetUsingSpecificClient(c *http.Client, url string) (resp *http.Response, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return
}
//shadowrocket会有可能不清楚alterid的情况,影响aead是否启用的问题
req.Header.Set("User-Agent", fmt.Sprintf("v2rayA/%v WebRequestHelper", conf.Version))
if resp, err = c.Do(req); err != nil {
resp, err = http.DefaultClient.Do(req)
}
if resp == nil {
cause := err
var urlErr *neturl.Error
if errors.As(cause, &urlErr) {
cause = urlErr.Err
}
if cause == nil {
cause = errors.New("request returned no response")
}
return nil, fmt.Errorf("could not reach %s: %w", req.URL.Hostname(), cause)
}
return
}