Overview
TheTransportOptions type provides fine-grained control over the HTTP transport layer, including connection pooling, idle timeouts, buffer sizes, and TLS debugging capabilities.
Type definition
Fields
An
io.Writer that the TLS client will use to write the TLS master secrets to. This can be used to decrypt TLS connections in Wireshark and other network analysis tools.Use case: Debugging TLS traffic by logging session keys to a file.The maximum amount of time an idle (keep-alive) connection will remain idle before closing itself. Zero means no limit.Default: No specific default when nil.
The set of root certificate authorities used to verify the remote server’s certificate.Use case: Custom certificate validation or adding self-signed certificates.
Controls the maximum number of idle (keep-alive) connections across all hosts.Default: System default when set to 0.
Controls the maximum idle (keep-alive) connections to keep per-host.Default: System default when set to 0.
Limits the total number of connections per host, including dialing, active, and idle states.Default: No limit when set to 0.
Specifies a limit on how many response header bytes are allowed. Zero means to use a default limit.Use case: Preventing memory exhaustion from malicious servers sending extremely large headers.
The size of the write buffer. If zero, a default (currently 4KB) is used.Use case: Optimizing throughput for high-bandwidth connections.
The size of the read buffer. If zero, a default (currently 4KB) is used.Use case: Optimizing throughput for high-bandwidth connections.
If true, disables HTTP keep-alives and will only use the connection to the server for a single HTTP request.Default: false (keep-alives enabled).
If true, prevents the Transport from requesting compression with an “Accept-Encoding: gzip” request header.Default: false (compression enabled).
Usage examples
TLS debugging with Wireshark
Export TLS session keys to decrypt traffic in network analysis tools:Connection pooling optimization
Configure connection limits for high-throughput scenarios:Custom root CA
Add custom certificate authorities for enterprise environments:Performance tuning
Optimize buffer sizes for large file transfers:Disable compression
Prevent automatic compression for pre-compressed content:Related options
- Use
WithTransportOptions()to apply transport settings to a client - See
WithInsecureSkipVerify()for disabling certificate verification - See
WithTimeoutSeconds()for request-level timeouts