03 — HTTP Protocol Configuration
The HttpProtocolBuilder defines defaults shared by every HTTP request in the simulation. Configure it once and pass it to setUp.
Base URL
// Java
HttpProtocolBuilder httpProtocol = http.baseUrl("https://api.example.com");
// Kotlin
val httpProtocol = http.baseUrl("https://api.example.com")
All relative request paths are resolved against this URL. You can also provide multiple base URLs for round-robin load balancing:
Headers
HttpProtocolBuilder httpProtocol = http
.baseUrl("https://api.example.com")
.acceptHeader("application/json")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("en-US,en;q=0.5")
.contentTypeHeader("application/json")
.userAgentHeader("Gatling LoadTest/1.0")
.header("X-Api-Version", "2");
Per-request headers override protocol-level headers.
Authentication
Basic auth
Bearer token (static)
Bearer token (dynamic — from session)
// Per-request (see 08-session.md for how to save the token)
http("Secure endpoint").get("/profile")
.header("Authorization", session -> "Bearer " + session.getString("authToken"))
Digest auth
Connection management
http
.maxConnectionsPerHost(6) // default browser-like limit
.shareConnections() // all virtual users share connection pool
.disableFollowRedirect() // don't follow 3xx
.maxRedirects(5) // default is 20
TLS / HTTPS
TLS trust store configuration is done via gatling.conf, not the DSL.
For self-signed certificates in dev environments, set in gatling.conf:
gatling {
http {
ssl {
trustStore {
type = "JKS"
file = "certs/truststore.jks"
password = "changeit"
}
}
}
}
Proxy
Timeouts
Global defaults are configured in gatling.conf:
gatling {
http {
requestTimeout = 10000 # ms
pooledConnectionIdleTimeout = 60000
connectionTimeout = 10000
}
}
You can override the request timeout per-request via the DSL:
Automatic checks applied globally
You can add checks that apply to every request without repeating them:
Full example
Java
HttpProtocolBuilder httpProtocol = http
.baseUrl("https://api.example.com")
.acceptHeader("application/json")
.contentTypeHeader("application/json")
.userAgentHeader("Gatling/3.15")
.authorizationHeader("Bearer static-token")
.maxConnectionsPerHost(10)
.check(status().not(500));