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.
Arguments
- code
Code to execture
- verbosity
How much information to print? This is a wrapper around
req_verbose()
that uses an integer to control verbosity:0
: no output1
: show headers2
: show headers and bodies3
: show headers, bodies, and curl status messages.
Use
with_verbosity()
to control the verbosity of requests that you can't affect directly.- env
Environment to use for scoping changes.
Value
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.
Examples
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.1.1.9000 r-curl/6.2.1 libcurl/8.5.0
#> -> Accept: */*
#> -> Accept-Encoding: deflate, gzip, br, zstd
#> ->
#> <- HTTP/2 200
#> <- server: GitHub.com
#> <- content-type: text/html; charset=utf-8
#> <- last-modified: Sat, 08 Mar 2025 18:44:46 GMT
#> <- access-control-allow-origin: *
#> <- etag: W/"67cc901e-4b42"
#> <- expires: Sat, 08 Mar 2025 18:56:55 GMT
#> <- cache-control: max-age=600
#> <- content-encoding: gzip
#> <- x-proxy-cache: MISS
#> <- x-github-request-id: C7FC:2C5C92:2803F34:2AF6D18:67CC909F
#> <- accept-ranges: bytes
#> <- date: Sat, 08 Mar 2025 18:47:15 GMT
#> <- via: 1.1 varnish
#> <- age: 21
#> <- x-served-by: cache-iad-kcgs7200174-IAD
#> <- x-cache: HIT
#> <- x-cache-hits: 5
#> <- x-timer: S1741459636.690587,VS0,VE1
#> <- vary: Accept-Encoding
#> <- x-fastly-request-id: 7bd35fd9304da20d8857884df17a6274a36daac2
#> <- content-length: 4746
#> <-
#> <httr2_response>
#> GET https://httr2.r-lib.org/
#> Status: 200 OK
#> Content-Type: text/html
#> Body: In memory (19266 bytes)
fun <- function() {
local_verbosity(2)
# someotherpackage::fun()
}