Context
In order to test the web capabilities of an R package I am writing, I'm attempting to serve a file locally use the httpuv
package so that I can run tests using an offline copy of the page.
Issue
However, curl
doesn't seem to want to play nice with httpuv
- specifically, when trying to read the hosted file using curl
(for example, with curl::curl()
or curl::curl_fetch_memory()
), the request hangs, and eventually times out if not manually interrupted.
Minimal example
# Serve a small page
server <- httpuv::startServer("0.0.0.0", port = 9359, app = list(
call = function(req) {
list(
status = 200L,
headers = list("Content-Type" = "text/html"),
body = "Some content..."
)
}
))
# Attempt to retrieve content (this hangs)
page <- curl::curl_fetch_memory(url = "http://127.0.0.1:9359")
httpuv::stopServer(server)
Current progress
Once the server has been started, running curl -v 127.0.0.1:9359
at the terminal returns content as expected. Additionally, if I open a new instance of RStudio and try to curl::curl_fetch_memory()
in that new R session (while the old one is still open), it works perfectly.
Encouraged by that, I've been playing around with callr
for a while, thinking maybe it's possible to launch the server in some background process, and then continue as usual. Unfortunately I haven't had any success so far with this approach.
Any insight or suggestions very much appreciated!