mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
style(amp): tidy whitespace in proxy module and tests
This commit is contained in:
@@ -181,5 +181,3 @@ func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error {
|
|||||||
log.Debug("Amp config updated (restart required for URL changes)")
|
log.Debug("Amp config updated (restart required for URL changes)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func createReverseProxy(upstreamURL string, secretSource SecretSource) (*httputi
|
|||||||
// Peek at first 2 bytes to detect gzip magic bytes
|
// Peek at first 2 bytes to detect gzip magic bytes
|
||||||
header := make([]byte, 2)
|
header := make([]byte, 2)
|
||||||
n, _ := io.ReadFull(originalBody, header)
|
n, _ := io.ReadFull(originalBody, header)
|
||||||
|
|
||||||
// Check for gzip magic bytes (0x1f 0x8b)
|
// Check for gzip magic bytes (0x1f 0x8b)
|
||||||
// If n < 2, we didn't get enough bytes, so it's not gzip
|
// If n < 2, we didn't get enough bytes, so it's not gzip
|
||||||
if n >= 2 && header[0] == 0x1f && header[1] == 0x8b {
|
if n >= 2 && header[0] == 0x1f && header[1] == 0x8b {
|
||||||
@@ -97,7 +97,7 @@ func createReverseProxy(upstreamURL string, secretSource SecretSource) (*httputi
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reconstruct complete gzipped data
|
// Reconstruct complete gzipped data
|
||||||
gzippedData := append(header[:n], rest...)
|
gzippedData := append(header[:n], rest...)
|
||||||
|
|
||||||
@@ -129,8 +129,8 @@ func createReverseProxy(upstreamURL string, secretSource SecretSource) (*httputi
|
|||||||
resp.ContentLength = int64(len(decompressed))
|
resp.ContentLength = int64(len(decompressed))
|
||||||
|
|
||||||
// Update headers to reflect decompressed state
|
// Update headers to reflect decompressed state
|
||||||
resp.Header.Del("Content-Encoding") // No longer compressed
|
resp.Header.Del("Content-Encoding") // No longer compressed
|
||||||
resp.Header.Del("Content-Length") // Remove stale compressed length
|
resp.Header.Del("Content-Length") // Remove stale compressed length
|
||||||
resp.Header.Set("Content-Length", strconv.FormatInt(resp.ContentLength, 10)) // Set decompressed length
|
resp.Header.Set("Content-Length", strconv.FormatInt(resp.ContentLength, 10)) // Set decompressed length
|
||||||
|
|
||||||
log.Debugf("amp proxy: decompressed gzip response (%d -> %d bytes)", len(gzippedData), len(decompressed))
|
log.Debugf("amp proxy: decompressed gzip response (%d -> %d bytes)", len(gzippedData), len(decompressed))
|
||||||
|
|||||||
@@ -440,52 +440,52 @@ func TestIsStreamingResponse(t *testing.T) {
|
|||||||
|
|
||||||
func TestFilterBetaFeatures(t *testing.T) {
|
func TestFilterBetaFeatures(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
featureToRemove string
|
featureToRemove string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Remove context-1m from middle",
|
name: "Remove context-1m from middle",
|
||||||
header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07,oauth-2025-04-20",
|
header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07,oauth-2025-04-20",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
expected: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Remove context-1m from start",
|
name: "Remove context-1m from start",
|
||||||
header: "context-1m-2025-08-07,fine-grained-tool-streaming-2025-05-14",
|
header: "context-1m-2025-08-07,fine-grained-tool-streaming-2025-05-14",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "fine-grained-tool-streaming-2025-05-14",
|
expected: "fine-grained-tool-streaming-2025-05-14",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Remove context-1m from end",
|
name: "Remove context-1m from end",
|
||||||
header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07",
|
header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "fine-grained-tool-streaming-2025-05-14",
|
expected: "fine-grained-tool-streaming-2025-05-14",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Feature not present",
|
name: "Feature not present",
|
||||||
header: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
header: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
expected: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Only feature to remove",
|
name: "Only feature to remove",
|
||||||
header: "context-1m-2025-08-07",
|
header: "context-1m-2025-08-07",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "",
|
expected: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty header",
|
name: "Empty header",
|
||||||
header: "",
|
header: "",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "",
|
expected: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Header with spaces",
|
name: "Header with spaces",
|
||||||
header: "fine-grained-tool-streaming-2025-05-14, context-1m-2025-08-07 , oauth-2025-04-20",
|
header: "fine-grained-tool-streaming-2025-05-14, context-1m-2025-08-07 , oauth-2025-04-20",
|
||||||
featureToRemove: "context-1m-2025-08-07",
|
featureToRemove: "context-1m-2025-08-07",
|
||||||
expected: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
expected: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/claude"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/claude"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/gemini"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/gemini"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/openai"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/openai"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -826,7 +826,6 @@ func (r *ModelRegistry) CleanupExpiredQuotas() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetFirstAvailableModel returns the first available model for the given handler type.
|
// GetFirstAvailableModel returns the first available model for the given handler type.
|
||||||
// It prioritizes models by their creation timestamp (newest first) and checks if they have
|
// It prioritizes models by their creation timestamp (newest first) and checks if they have
|
||||||
// available clients that are not suspended or over quota.
|
// available clients that are not suspended or over quota.
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func (h *GeminiAPIHandler) GeminiGetHandler(c *gin.Context) {
|
|||||||
switch request.Action {
|
switch request.Action {
|
||||||
case "gemini-3-pro-preview":
|
case "gemini-3-pro-preview":
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"name": "gemini-3-pro-preview",
|
"name": "models/gemini-3-pro-preview",
|
||||||
"version": "3",
|
"version": "3",
|
||||||
"displayName": "Gemini 3 Pro Preview",
|
"displayName": "Gemini 3 Pro Preview",
|
||||||
"description": "Gemini 3 Pro Preview",
|
"description": "Gemini 3 Pro Preview",
|
||||||
|
|||||||
Reference in New Issue
Block a user