Repository navigation
feat: use proxy HTTP client fetch models - #1584
Conversation
WalkthroughUpdated GetResponseBody in controller/channel-billing.go to build and use a channel-specific proxy HTTP client based on channel settings. If proxy client creation fails, it returns an error; otherwise, it performs the request via the constructed client. Response handling logic remains the same. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Caller
participant B as GetResponseBody
participant F as ProxyClientFactory
participant H as HTTP Client
participant U as Upstream Service
C->>B: GetResponseBody(req, channel)
B->>F: Create client with channel.GetSetting().Proxy
alt Client creation fails
F-->>B: Error
B-->>C: Return error
else Success
F-->>B: Proxy HTTP client
B->>H: client.Do(req)
H->>U: HTTP request (via proxy if set)
U-->>H: HTTP response
H-->>B: Response
B-->>C: Processed response
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
controller/channel-billing.go (1)
138-142: Consider fallback behavior when proxy creation fails.While the current implementation correctly returns an error when proxy client creation fails, consider whether a fallback to a default HTTP client would be more appropriate for better availability, especially if proxy configuration is optional.
If proxy usage should be optional and fall back to default behavior when proxy setup fails, consider this approach:
- client, err := service.NewProxyHttpClient(channel.GetSetting().Proxy) - if err != nil { - return nil, err - } + client, err := service.NewProxyHttpClient(channel.GetSetting().Proxy) + if err != nil { + // Log the proxy setup failure and fallback to default client + common.SysLog(fmt.Sprintf("Failed to create proxy client for channel %d: %v, using default client", channel.Id, err)) + client = &http.Client{Timeout: 30 * time.Second} + }However, if proxy usage is mandatory when configured, the current error-returning approach is correct.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
controller/channel-billing.go(1 hunks)
🔇 Additional comments (1)
controller/channel-billing.go (1)
138-142: Verified service.NewProxyHttpClient implementation and error handlingThe
NewProxyHttpClientfunction is defined inservice/http_client.go:32and correctly handles all supported proxy scenarios:
- Returns
http.DefaultClientwhenproxyURLis empty.- Parses the provided URL and returns an error on parse failure.
- Supports “http”/“https” schemes via
http.Transport{ Proxy: http.ProxyURL(...) }.- Supports “socks5”/“socks5h” schemes with a SOCKS5 dialer (including optional authentication).
- Returns a clear error for any unsupported proxy scheme.
No changes are required here.
…ch-models feat: use proxy HTTP client fetch models
…ch-models feat: use proxy HTTP client fetch models
…ch-models feat: use proxy HTTP client fetch models
支持渠道获取模型时使用代理

Summary by CodeRabbit