From 6c17dbc4dacd42f34039b1da85b3fe1c54be2c1a Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:57:26 +0800 Subject: [PATCH] style(amp): tidy whitespace in proxy module and tests --- internal/api/modules/amp/amp.go | 2 - internal/api/modules/amp/proxy.go | 8 ++-- internal/api/modules/amp/proxy_test.go | 48 +++++++++++----------- internal/api/modules/amp/routes.go | 2 +- internal/registry/model_registry.go | 1 - sdk/api/handlers/gemini/gemini_handlers.go | 2 +- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/internal/api/modules/amp/amp.go b/internal/api/modules/amp/amp.go index f95218ae..0086d179 100644 --- a/internal/api/modules/amp/amp.go +++ b/internal/api/modules/amp/amp.go @@ -181,5 +181,3 @@ func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error { log.Debug("Amp config updated (restart required for URL changes)") return nil } - - diff --git a/internal/api/modules/amp/proxy.go b/internal/api/modules/amp/proxy.go index d417d068..33f32c28 100644 --- a/internal/api/modules/amp/proxy.go +++ b/internal/api/modules/amp/proxy.go @@ -83,7 +83,7 @@ func createReverseProxy(upstreamURL string, secretSource SecretSource) (*httputi // Peek at first 2 bytes to detect gzip magic bytes header := make([]byte, 2) n, _ := io.ReadFull(originalBody, header) - + // Check for gzip magic bytes (0x1f 0x8b) // If n < 2, we didn't get enough bytes, so it's not gzip if n >= 2 && header[0] == 0x1f && header[1] == 0x8b { @@ -97,7 +97,7 @@ func createReverseProxy(upstreamURL string, secretSource SecretSource) (*httputi } return nil } - + // Reconstruct complete gzipped data gzippedData := append(header[:n], rest...) @@ -129,8 +129,8 @@ func createReverseProxy(upstreamURL string, secretSource SecretSource) (*httputi resp.ContentLength = int64(len(decompressed)) // Update headers to reflect decompressed state - resp.Header.Del("Content-Encoding") // No longer compressed - resp.Header.Del("Content-Length") // Remove stale compressed length + resp.Header.Del("Content-Encoding") // No longer compressed + resp.Header.Del("Content-Length") // Remove stale compressed 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)) diff --git a/internal/api/modules/amp/proxy_test.go b/internal/api/modules/amp/proxy_test.go index a9694c01..95edc12d 100644 --- a/internal/api/modules/amp/proxy_test.go +++ b/internal/api/modules/amp/proxy_test.go @@ -440,52 +440,52 @@ func TestIsStreamingResponse(t *testing.T) { func TestFilterBetaFeatures(t *testing.T) { tests := []struct { - name string - header string + name string + header string featureToRemove string - expected string + expected string }{ { - name: "Remove context-1m from middle", - header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07,oauth-2025-04-20", + name: "Remove context-1m from middle", + header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07,oauth-2025-04-20", 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", - header: "context-1m-2025-08-07,fine-grained-tool-streaming-2025-05-14", + name: "Remove context-1m from start", + header: "context-1m-2025-08-07,fine-grained-tool-streaming-2025-05-14", 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", - header: "fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07", + name: "Remove context-1m from end", + header: "fine-grained-tool-streaming-2025-05-14,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", - header: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20", + name: "Feature not present", + header: "fine-grained-tool-streaming-2025-05-14,oauth-2025-04-20", 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", - header: "context-1m-2025-08-07", + name: "Only feature to remove", + header: "context-1m-2025-08-07", featureToRemove: "context-1m-2025-08-07", - expected: "", + expected: "", }, { - name: "Empty header", - header: "", + name: "Empty header", + header: "", featureToRemove: "context-1m-2025-08-07", - expected: "", + expected: "", }, { - name: "Header with spaces", - header: "fine-grained-tool-streaming-2025-05-14, context-1m-2025-08-07 , oauth-2025-04-20", + name: "Header with spaces", + header: "fine-grained-tool-streaming-2025-05-14, context-1m-2025-08-07 , oauth-2025-04-20", 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", }, } diff --git a/internal/api/modules/amp/routes.go b/internal/api/modules/amp/routes.go index 43d140e6..8e5189ad 100644 --- a/internal/api/modules/amp/routes.go +++ b/internal/api/modules/amp/routes.go @@ -6,11 +6,11 @@ import ( "strings" "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/claude" "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/internal/util" log "github.com/sirupsen/logrus" ) diff --git a/internal/registry/model_registry.go b/internal/registry/model_registry.go index 1fb307be..5ef9007f 100644 --- a/internal/registry/model_registry.go +++ b/internal/registry/model_registry.go @@ -826,7 +826,6 @@ func (r *ModelRegistry) CleanupExpiredQuotas() { } } - // 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 // available clients that are not suspended or over quota. diff --git a/sdk/api/handlers/gemini/gemini_handlers.go b/sdk/api/handlers/gemini/gemini_handlers.go index 1f8828d5..7ba72a93 100644 --- a/sdk/api/handlers/gemini/gemini_handlers.go +++ b/sdk/api/handlers/gemini/gemini_handlers.go @@ -71,7 +71,7 @@ func (h *GeminiAPIHandler) GeminiGetHandler(c *gin.Context) { switch request.Action { case "gemini-3-pro-preview": c.JSON(http.StatusOK, gin.H{ - "name": "gemini-3-pro-preview", + "name": "models/gemini-3-pro-preview", "version": "3", "displayName": "Gemini 3 Pro Preview", "description": "Gemini 3 Pro Preview",