HTTP Client Configuration

March 15, 2026 ยท View on GitHub

Overview

The Salesforce Go client now supports custom HTTP transport layer configuration, allowing you to:

  1. Provide a custom http.RoundTripper - Lower-level control over HTTP request/response cycle
    • http.RoundTripper can be layered to allow for logging, observability, etc layers for each request
  2. Use default HTTP client - Sensible defaults are provided when no custom configuration is specified

Usage Examples

Custom Round Tripper

func main() {
    // Create a custom round tripper for fine-grained HTTP control\
    // options include proxy, tls, etc
    proxyURL, _ := url.Parse("http://my-proxy:8080")
    customRoundTripper := &http.Transport{
        TLSClientConfig: &tls.Config{
            MinVersion: tls.VersionTLS12,
        },
        MaxIdleConns:        10,
        IdleConnTimeout:     30 * time.Second,
        DisableCompression:  false,
        DisableKeepAlives:   false,
        MaxIdleConnsPerHost: 5,
        Proxy: http.ProxyURL(proxyURL), // optional
    }

    creds := salesforce.Creds{
        // ... your credentials
    }

    // Initialize with custom round tripper
    sf, err := salesforce.Init(creds, 
        salesforce.WithRoundTripper(customRoundTripper),
        salesforce.WithAPIVersion("v64.0"),
    )
    if err != nil {
        log.Fatal(err)
    }
}

Configuration Options

HTTP Client Options

OptionDescriptionDefault
WithRoundTripper(rt http.RoundTripper)Set a custom round tripperDefault transport

Other Configuration Options

OptionDescriptionDefault
WithAPIVersion(version string)Set Salesforce API versionv63.0
WithCompressionHeaders(enabled bool)Enable/disable compressionfalse
WithBatchSizeMax(size int)Set max batch size for collections200
WithBulkBatchSizeMax(size int)Set max batch size for bulk operations10000
WithBulkPollTimeout(timeout time.Duration)Set timeout for polling bulk results1m

Default HTTP Client Configuration

When no custom round tripper is provided, the library uses:

&http.Client{
    Timeout: 120 * time.Second,
    Transport: &http.Transport{
        MaxIdleConns:       10,
        IdleConnTimeout:    30 * time.Second,
        DisableCompression: false,
    },
}

Accessing Configuration

You can retrieve the current configuration using getter methods:

sf, _ := salesforce.Init(creds)

// Get the configured HTTP client
client := sf.GetHTTPClient()

// Get other configuration values
apiVersion := sf.GetAPIVersion()
batchSizeMax := sf.GetBatchSizeMax()
bulkBatchSizeMax := sf.GetBulkBatchSizeMax()
compressionEnabled := sf.GetCompressionHeaders()

Implementation Details

  • The doRequest function now uses the configured HTTP client instead of http.DefaultClient
  • The API version from configuration is used in all endpoint URLs
  • Custom configurations are validated during initialization to prevent runtime errors

Migration from Previous Versions

This change is fully backward compatible. Existing code will continue to work without any modifications, using the default HTTP client configuration.