feat: 代理调试版本

This commit is contained in:
tbphp
2025-07-11 14:01:54 +08:00
parent 395d48c3e7
commit 6ffbb7e9a1
13 changed files with 568 additions and 255 deletions

View File

@@ -3,22 +3,35 @@ package channel
import (
"context"
"gpt-load/internal/models"
"net/http"
"net/url"
"github.com/gin-gonic/gin"
)
// ChannelProxy defines the interface for different API channel proxies.
// It's responsible for channel-specific logic like URL building and request modification.
type ChannelProxy interface {
// Handle takes a context, an API key, and the original request,
// then forwards the request to the upstream service.
Handle(c *gin.Context, apiKey *models.APIKey, group *models.Group) error
// BuildUpstreamURL constructs the target URL for the upstream service.
BuildUpstreamURL(originalURL *url.URL, group *models.Group) (string, error)
// ModifyRequest allows the channel to add specific headers or modify the request
// before it's sent to the upstream service.
ModifyRequest(req *http.Request, apiKey *models.APIKey, group *models.Group)
// IsStreamRequest checks if the request is for a streaming response,
// now using the cached request body to avoid re-reading the stream.
IsStreamRequest(c *gin.Context, bodyBytes []byte) bool
// ValidateKey checks if the given API key is valid.
ValidateKey(ctx context.Context, key string) (bool, error)
// IsStreamingRequest checks if the request is for a streaming response.
IsStreamingRequest(c *gin.Context) bool
// IsConfigStale checks if the channel's configuration is stale compared to the provided group.
IsConfigStale(group *models.Group) bool
// GetHTTPClient returns the client for standard requests.
GetHTTPClient() *http.Client
// GetStreamClient returns the client for streaming requests.
GetStreamClient() *http.Client
}