Arbitrary headers can be set on the request using the .header method:

import sttp.client3._



As with any other request definition modifier, this method will yield a new request, which has the given header set. The headers can be set at any point when defining the request, arbitrarily interleaved with other modifiers.

While most headers should be set only once on a request, HTTP allows setting a header multiple times. That’s why the header method has an additional optional boolean parameter, replaceExisting, which defaults to true. This way, if the same header is specified twice, only the last value will be included in the request. If previous values should be preserved, set this parameter to false.

There are also variants of this method accepting a number of headers:

import sttp.client3._
import sttp.model._

basicRequest.headers(Map("k4" -> "v4", "k5" -> "v5"))


import sttp.client3._