fix(osi): 加固 Phase 0 验收实现(T-006)
This commit is contained in:
+2
-7
@@ -23,7 +23,6 @@ type TransportConfig struct {
|
||||
}
|
||||
|
||||
type Transport struct {
|
||||
client *http.Client
|
||||
timeout time.Duration
|
||||
dialer proxy.Dialer
|
||||
}
|
||||
@@ -35,19 +34,15 @@ func NewTransport(config TransportConfig) (*Transport, error) {
|
||||
}
|
||||
|
||||
dialer := proxy.Dialer(proxy.Direct)
|
||||
roundTripper := http.DefaultTransport.(*http.Transport).Clone()
|
||||
if strings.TrimSpace(config.Socks5Proxy) != "" {
|
||||
proxyDialer, err := socks5Dialer(config.Socks5Proxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dialer = proxyDialer
|
||||
roundTripper.DialContext = func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return dialWithContext(ctx, proxyDialer, network, address)
|
||||
}
|
||||
}
|
||||
|
||||
return &Transport{client: &http.Client{Timeout: timeout, Transport: roundTripper}, timeout: timeout, dialer: dialer}, nil
|
||||
return &Transport{timeout: timeout, dialer: dialer}, nil
|
||||
}
|
||||
|
||||
func (t *Transport) PostJSON(ctx context.Context, targetURL string, payload any, headers map[string]string) (int, []byte, error) {
|
||||
@@ -107,7 +102,7 @@ func writeJSONRequest(w io.Writer, target *url.URL, body []byte, headers map[str
|
||||
fmt.Fprintf(&buf, "POST %s HTTP/1.1\r\n", path)
|
||||
writeHeader(&buf, "Host", target.Host)
|
||||
writeHeader(&buf, "User-Agent", headerValue(headers, "User-Agent", "python-requests/2.32.4"))
|
||||
writeHeader(&buf, "Accept-Encoding", headerValue(headers, "Accept-Encoding", "gzip, deflate, br"))
|
||||
writeHeader(&buf, "Accept-Encoding", headerValue(headers, "Accept-Encoding", "identity"))
|
||||
writeHeader(&buf, "Accept", headerValue(headers, "Accept", "*/*"))
|
||||
writeHeader(&buf, "Connection", headerValue(headers, "Connection", "keep-alive"))
|
||||
writeHeader(&buf, "Content-Length", fmt.Sprintf("%d", len(body)))
|
||||
|
||||
Reference in New Issue
Block a user