This shows you exactly what httr2 will send to the server, without
actually sending anything. It requires the httpuv package because it
works by sending the real HTTP request to a local webserver, thanks to
the magic of curl::curl_echo().
req_dry_run(
req,
quiet = FALSE,
redact_headers = TRUE,
testing_headers = is_testing(),
pretty_json = getOption("httr2_pretty_json", TRUE)
)A httr2 request object.
If TRUE doesn't print anything.
Redact confidential data in the headers? Currently redacts the contents of the Authorization header to prevent you from accidentally leaking credentials when debugging/reprexing.
If TRUE, removes headers that httr2 would otherwise
be automatically added, which are likely to change across test runs. This
currently includes:
The default User-Agent, which varies based on libcurl, curl, and
httr2 versions.
The `Host“ header, which is often set to a testing server.
The Content-Length header, which will often vary by platform because
of varying newline encodings. (And is also not correct if you have
pretty_json = TRUE.)
The Accept-Encoding header, which varies based on how libcurl was
built.
If TRUE, automatically prettify JSON bodies.
Invisibly, a list containing information about the request,
including method, path, and headers.
# httr2 adds default User-Agent, Accept, and Accept-Encoding headers
request("http://example.com") |> req_dry_run()
#> GET / HTTP/1.1
#> accept: */*
#> accept-encoding: deflate, gzip, br, zstd
#> host: example.com
#> user-agent: httr2/1.1.2 r-curl/7.0.0 libcurl/7.81.0
#>
# the Authorization header is automatically redacted to avoid leaking
# credentials on the console
req <- request("http://example.com") |> req_auth_basic("user", "password")
req |> req_dry_run()
#> GET / HTTP/1.1
#> accept: */*
#> accept-encoding: deflate, gzip, br, zstd
#> authorization: <REDACTED>
#> host: example.com
#> user-agent: httr2/1.1.2 r-curl/7.0.0 libcurl/7.81.0
#>
# if you need to see it, use redact_headers = FALSE
req |> req_dry_run(redact_headers = FALSE)
#> GET / HTTP/1.1
#> accept: */*
#> accept-encoding: deflate, gzip, br, zstd
#> authorization: <REDACTED>
#> host: example.com
#> user-agent: httr2/1.1.2 r-curl/7.0.0 libcurl/7.81.0
#>