The predecessor R library of "httr2", that is "httr", provides methods to manage the requests handles.
The low level approach is:
h <- httr::handle("https://google.com/")
res <- httr::GET(handle = h)
Now, request settings are tied to h. For example, a new request keeps the same cookies.
(cs <- httr::cookies(res))
identical(httr::cookies(res), cs) # TRUE
To start from scratch, one resets the handle simply by generating a new one. That is:
h <- httr::handle("https://google.com/")
identical(httr::cookies(res), cs) # FALSE
As a (better) alternative, one can use the default handle and handle_reset():
c1 <- httr::cookies(httr::GET("https://google.com/"))
c2 <- httr::cookies(httr::GET("https://google.com/"))
identical(c1, c2) # TRUE
httr::handle_reset("https://google.com/")
c1 <- httr::cookies(httr::GET("https://google.com/"))
identical(c1, c2) # FALSE
Resetting the handle is necessary when you are testing authentications to websites and the state is kept in the cookies.
When it comes to "httr2", the manual doesn't even mention the handles. So I wonder how we can reset a connection, other than detaching the package and loading it again.
There is this documentation about how to preserve cookies between across requests.
Then, if you provide different cookies file paths, you'll get separate request session states.