with_verbosity() and local_verbosity() are useful for debugging httr2
code buried deep inside another package, because they allow you to change
the verbosity even when you don't have access to the request.
Both functions work by temporarily setting the httr2_verbosity option. You
can also control verbosity by setting the HTTR2_VERBOSITY environment
variable. This has lower precedence than the option, but can be more easily
changed outside of R.
with_verbosity(code, verbosity = 1)
local_verbosity(verbosity, env = caller_env())Code to execture
How much information to print? This is a wrapper
around req_verbose() that uses an integer to control verbosity:
0: no output
1: show headers
2: show headers and bodies
3: show headers, bodies, and curl status messages.
Use with_verbosity() to control the verbosity of requests that
you can't affect directly.
Environment to use for scoping changes.
with_verbosity() returns the result of evaluating code.
local_verbosity() is called for its side-effect and invisibly returns
the previous value of the option.
fun <- function() {
request("https://httr2.r-lib.org") |> req_perform()
}
with_verbosity(fun())
#> -> GET / HTTP/2
#> -> Host: httr2.r-lib.org
#> -> user-agent: httr2/1.2.1 r-curl/6.4.0 libcurl/7.81.0
#> -> accept: */*
#> -> accept-encoding: deflate, gzip, br, zstd
#> ->
#> <- HTTP/2 200
#> <- server: GitHub.com
#> <- content-type: text/html; charset=utf-8
#> <- last-modified: Thu, 24 Jul 2025 14:49:24 GMT
#> <- access-control-allow-origin: *
#> <- etag: W/"688247f4-4ae0"
#> <- expires: Tue, 29 Jul 2025 17:48:48 GMT
#> <- cache-control: max-age=600
#> <- content-encoding: gzip
#> <- x-proxy-cache: MISS
#> <- x-github-request-id: 08C2:2C9EE1:1FC6674:220D099:68890727
#> <- accept-ranges: bytes
#> <- date: Tue, 29 Jul 2025 19:05:21 GMT
#> <- via: 1.1 varnish
#> <- age: 24
#> <- x-served-by: cache-cmh1290081-CMH
#> <- x-cache: HIT
#> <- x-cache-hits: 5
#> <- x-timer: S1753815921.065513,VS0,VE0
#> <- vary: Accept-Encoding
#> <- x-fastly-request-id: 02a6d1eacbc499932e82e75ed9a2cfe78ae37029
#> <- content-length: 4768
#> <-
#> <httr2_response>
#> GET https://httr2.r-lib.org/
#> Status: 200 OK
#> Content-Type: text/html
#> Body: In memory (19168 bytes)
fun <- function() {
local_verbosity(2)
# someotherpackage::fun()
}