Settings reference

Every setting of the client in one place: what it does, how to set it, how to read it back, and its default. The guides explain when you need each one. This page is for looking a setting up.

Table of Contents

Request settings

Set these on a ClientRequest with the builder functions. They apply to that request only. A getter returns None for a setting that the request doesn’t set, and the request then uses the default in the last column.

SettingSet withRead withDefault
Methodmethod(request, http.Post)get_methodhttp.Get
Schemescheme(request, http.Http)get_schemehttp.Https
Hosthost(request, "api.example.com")get_host"localhost"
Portport(request, 8080)get_portNone: 80 for HTTP, 443 for HTTPS
Pathpath(request, "/users")get_path""
Queryquery(request, "page=2")get_queryNone
Headersheaders(request, [Header(..)]), add_header(request, name, value)get_headers[]
Bodybody(request, text), body_bits(request, bytes)get_body<<>>
Timeout: the longest wait for the server, in mstimeout(request, ms)get_timeoutNone: 30000
Connect timeout, in msconnect_timeout(request, ms)get_connect_timeoutNone: the transport’s default_connect_timeout, 15000
Follow redirects (at most 5)auto_redirect(request, False)get_auto_redirectNone: follow
HTTP versionprotocols(request, Http2Only)get_protocolsNone: see Protocols
Certificate authority filecertificate_authority_file(request, path)get_certificate_authority_fileNone: the transport’s default_certificate_authority_file, or the system authorities
Connection poolpool(request, new_pool(max_connections: n))get_pool, and get_pool_max_connections for its limitNone: the shared pool, limited by max_connections
Recorderrecorder(request, recorder)get_recorderNone

Guides: Sending data to an API for the request parts, Handling errors, timeouts and retries for the timeouts and redirects, Controlling connections for protocols and pools, and Calling a service with a private certificate authority for the certificate authority file.

Stream callbacks

start_stream calls these in the stream’s own process. Each one is optional.

CallbackSet withCalled with
The response headers arrivedon_stream_start(request, fn(headers))List(Header)
The next part of the body arrivedon_stream_chunk(request, fn(data))BitArray
The body is completeon_stream_end(request, fn(trailers))List(Header), the trailing headers, often empty
The stream failedon_stream_error(request, fn(failure))StreamFailure

Guide: Streaming a response.

Transport settings

These apply to every request. Build a TransportConfig with transport_config() and the setting functions, then apply it with configure_transport(config). configure_transport sets every setting of the configuration, so a setting you don’t set goes back to its default.

SettingSet withRead withDefault
Connections to each hostmax_connections(config, n)get_max_connections50
Idle time before the pool closes a connection, in ms. A new value applies at onceidle_timeout(config, ms)get_idle_timeout60000
Connect timeout of a request that sets none, in msdefault_connect_timeout(config, ms)get_default_connect_timeout15000
DNS lookup timeout, in msdomain_lookup_timeout(config, ms)get_domain_lookup_timeout5000
TLS handshake timeout, in mstls_handshake_timeout(config, ms)get_tls_handshake_timeout10000
HTTP/2 ping interval, in mskeepalive(config, ms)get_keepalive30000
HTTP/2 pings without an answer before the connection closeskeepalive_tolerance(config, n)get_keepalive_tolerance3
HTTP/2 SETTINGS_MAX_CONCURRENT_STREAMS that the client sends to the servermax_concurrent_streams(config, n)get_max_concurrent_streams100
HTTP/2 connection flow-control window, in bytesinitial_connection_window_size(config, bytes)get_initial_connection_window_size65535
HTTP/2 stream flow-control window, in bytesinitial_stream_window_size(config, bytes)get_initial_stream_window_size65535
Wait for a graceful close, in msclosing_timeout(config, ms)get_closing_timeout15000
Certificate authority file of a request that sets nonedefault_certificate_authority_file(config, path)get_default_certificate_authority_fileNone: the system authorities
Log levellog_level(config, level)get_log_levelLogWarning

Guide: Controlling connections.

Protocols

The values of protocols(request, value):

ValueOver HTTPSOver plain HTTP
Not setOffers HTTP/2 and HTTP/1.1 in the TLS handshake, and the server picksHTTP/1.1
Http2PreferredOffers HTTP/2 and HTTP/1.1 in the TLS handshakeAsks to upgrade an HTTP/1.1 connection, which few servers support
Http2OnlyOffers only HTTP/2HTTP/2 from the first byte (“prior knowledge”)
Http1OnlyHTTP/1.1HTTP/1.1

Log levels

The values of log_level(config, value). The client writes every line through one module, and the level applies to all of its lines and to no other logging in your program. A new level applies when configure_transport returns.

ValueWhat the client writes
LogDebugEvery line. The client writes no debug lines, so this is the same as LogInfo
LogInfoThe info line connection closed, when a server closes an idle connection, and every warning
LogWarning (default)The warnings: a connection that went down with a request on it, a body the client can’t decompress, an unknown content encoding, a recorder that doesn’t answer, a recording file it can’t read correctly, and a recorded stream that failed
LogErrorNothing. The client writes no error lines
LogNoneNothing

See Controlling connections.

Recorder settings

Build a recorder with recorder.new() and these functions, then start it with recorder.start(builder).

SettingSet withDefault
Modemode(builder, recorder.Record), recorder.Playback or recorder.Passthrough. For a mode in a text, recorder.parse_mode("playback")recorder.Passthrough
Directory of the recording filesdirectory(builder, path)None. Record and playback mode need one: without it, start returns Error("Recorder directory is required for record/playback")
Match keykey(builder, matching.request_key(method:, url:, headers:, body:))method and URL
Request transformer, in every moderequest_transformer(builder, fn(request))no change
Response transformer, in record mode onlyresponse_transformer(builder, fn(request, response))no change

The match key also names the recording file: {method}_{host}_{path}_{key hash}.json, where the key hash is the first 16 hex characters of the SHA-256 of the key. A record run reads the directory at start, and the first recording of a key replaces the files that held that key. The files of the other keys stay.

The match key and the request transformer also decide what a playback miss shows. NoRecording names up to 3 recordings with the same method and path, nearest first, and only the parts that the key compares, after the request transformer. The recording guide gives the rule.

Guides: Testing with recorded responses and Matching requests and hiding secrets in recordings.

✨ Search Document