cc @aaronwolen
In our work to fix how webmockr/vcr handle bodies correctly, I noticed that we cannot re-create requests that have an upload passed directly to body (not in a list). This concerns this code block most importantly https://github.com/ropensci/vcr/blob/master/R/request_handler-httr.R#L102-L109 but also this https://github.com/ropensci/vcr/blob/master/R/request_handler-httr.R#L76-L81 if a user uses the ignored requests feature.
Re-creating what essentially is happening in those linked code blocks above, ...
This works (character string to body)
e <- POST("https://httpbin.org/post", body = "foo bar")
# re-create the request
POST("https://httpbin.org/post", do.call(config, e$request$options))
And this works (upload in a list)
b <- POST("https://httpbin.org/post",
body = list(y = upload_file(system.file("CITATION"))))
# re-create the request
POST("https://httpbin.org/post",
body = list(y = upload_file(system.file("CITATION"))),
do.call(config, b$request$options))
But this doesn't work (it just hangs indefinitely)
d <- POST("https://httpbin.org/post",
body = upload_file(system.file("CITATION")))
# re-create the request
POST("https://httpbin.org/post", do.call(config, d$request$options))
The problem stems from that we CAN get what's passed in the body from the request object created by httr EXCEPT when upload_file is passed directly to body (and there may be other cases I don't know about) . When upload_file is passed directly to body, the details are al in the $options in the request object, and there is no trace of the file path for the upload, or the content type. When an upload is passed in a list, we can get the needed information from the request.
The way webmockr/vcr are setup, I don't think we have access to what was passed to body originally, only what's in the httr $request object
Any thoughts on this @jennybc ?
cc @aaronwolen
In our work to fix how webmockr/vcr handle bodies correctly, I noticed that we cannot re-create requests that have an upload passed directly to body (not in a list). This concerns this code block most importantly https://github.com/ropensci/vcr/blob/master/R/request_handler-httr.R#L102-L109 but also this https://github.com/ropensci/vcr/blob/master/R/request_handler-httr.R#L76-L81 if a user uses the ignored requests feature.
Re-creating what essentially is happening in those linked code blocks above, ...
library(httr)This works (character string to body)
And this works (upload in a list)
But this doesn't work (it just hangs indefinitely)
The problem stems from that we CAN get what's passed in the body from the request object created by httr EXCEPT when upload_file is passed directly to body (and there may be other cases I don't know about) . When upload_file is passed directly to body, the details are al in the
$optionsin the request object, and there is no trace of the file path for the upload, or the content type. When an upload is passed in a list, we can get the needed information from the request.The way webmockr/vcr are setup, I don't think we have access to what was passed to
bodyoriginally, only what's in the httr$requestobjectAny thoughts on this @jennybc ?