refactor: consolidate duplicate UA and header scrubbing into shared misc functions

This commit is contained in:
maplelove
2026-02-27 10:57:13 +08:00
parent f3c164d345
commit fc0257d6d9
5 changed files with 72 additions and 83 deletions

View File

@@ -12,7 +12,6 @@ import (
"io"
"net/http"
"regexp"
"runtime"
"strconv"
"strings"
"time"
@@ -745,12 +744,7 @@ func applyGeminiCLIHeaders(r *http.Request, model string) {
ginHeaders = ginCtx.Request.Header
}
if model == "" {
model = "unknown"
}
userAgent := fmt.Sprintf("GeminiCLI/1.0.0/%s (%s; %s)", model, runtime.GOOS, runtime.GOARCH)
misc.EnsureHeader(r.Header, ginHeaders, "User-Agent", userAgent)
misc.EnsureHeader(r.Header, ginHeaders, "User-Agent", misc.GeminiCLIUserAgent(model))
}
// cliPreviewFallbackOrder returns preview model candidates for a base model.