misc

package
v6.10.9-aug.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package misc provides miscellaneous utility functions for the CLI Proxy API server. It includes helper functions for HTTP header manipulation and other common operations that don't fit into more specific packages.

Package misc provides miscellaneous utility functions and embedded data for the CLI Proxy API. This package contains general-purpose helpers and embedded resources that do not fit into more specific domain packages. It includes a comprehensive MIME type mapping for file operations.

Index

Constants

View Source
const (

	// GeminiCLIApiClientHeader is the value for the X-Goog-Api-Client header sent to the Gemini CLI upstream.
	GeminiCLIApiClientHeader = "google-genai-sdk/1.41.0 gl-node/v22.19.0"
)

Variables

View Source
var MimeTypes = map[string]string{}/* 732 elements not displayed */

MimeTypes is a comprehensive map of file extensions to their corresponding MIME types. This map is used to determine the Content-Type header for file uploads and other operations where the MIME type needs to be identified from a file extension. The list is extensive to cover a wide range of common and uncommon file formats.

Functions

func CopyConfigTemplate

func CopyConfigTemplate(src, dst string) error

func EnsureHeader

func EnsureHeader(target http.Header, source http.Header, key, defaultValue string)

EnsureHeader ensures that a header exists in the target header map by checking multiple sources in order of priority: source headers, existing target headers, and finally the default value. It only sets the header if it's not already present and the value is not empty after trimming whitespace.

Parameters:

  • target: The target header map to modify
  • source: The source header map to check first (can be nil)
  • key: The header key to ensure
  • defaultValue: The default value to use if no other source provides a value

func GeminiCLIUserAgent

func GeminiCLIUserAgent(model string) string

GeminiCLIUserAgent returns a User-Agent string that matches the Gemini CLI format. The model parameter is included in the UA; pass "" or "unknown" when the model is not applicable.

func GenerateRandomState

func GenerateRandomState() (string, error)

GenerateRandomState generates a cryptographically secure random state parameter for OAuth2 flows to prevent CSRF attacks.

Returns:

  • string: A hexadecimal encoded random state string
  • error: An error if the random generation fails, nil otherwise

func LogCredentialSeparator

func LogCredentialSeparator()

LogCredentialSeparator adds a visual separator to group auth/key processing logs.

func LogSavingCredentials

func LogSavingCredentials(path string)

LogSavingCredentials emits a consistent log message when persisting auth material.

func MergeMetadata

func MergeMetadata(source any, metadata map[string]any) (map[string]any, error)

MergeMetadata serializes the source struct into a map and merges the provided metadata into it.

func ScrubProxyAndFingerprintHeaders

func ScrubProxyAndFingerprintHeaders(req *http.Request)

ScrubProxyAndFingerprintHeaders removes all headers that could reveal proxy infrastructure, client identity, or browser fingerprints from an outgoing request. This ensures requests to upstream services look like they originate directly from a native client rather than a third-party client behind a reverse proxy.

Types

type OAuthCallback

type OAuthCallback struct {
	Code             string
	State            string
	Error            string
	ErrorDescription string
}

OAuthCallback captures the parsed OAuth callback parameters.

func ParseOAuthCallback

func ParseOAuthCallback(input string) (*OAuthCallback, error)

ParseOAuthCallback extracts OAuth parameters from a callback URL. It returns nil when the input is empty.

type PKCECodes

type PKCECodes struct {
	// CodeVerifier is the cryptographically random string used to correlate
	// the authorization request to the token request
	CodeVerifier string `json:"code_verifier"`
	// CodeChallenge is the SHA256 hash of the code verifier, base64url-encoded
	CodeChallenge string `json:"code_challenge"`
}

PKCECodes holds PKCE verification codes for OAuth2 PKCE flow.

func GeneratePKCECodes

func GeneratePKCECodes() (*PKCECodes, error)

GeneratePKCECodes generates a PKCE code verifier and challenge pair following RFC 7636 specifications for OAuth 2.0 PKCE extension.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL