有没有办法以编程方式捕获基于管道工的API响应的响应头?
这就是我所拥有的:
library(plumber)
library(futile.logger)
# creating a new router
router <- plumber::plumber$new()
# instancing a filter for logging request details
logFilter <- expression(function(req) {
# creating a log entry
req_data <- paste0(date(), "from ", req$REMOTE_ADDR #and so on)
# appending a log entry to a logger
flog.info(msg = req_data, name = "mylogger")
# passing the request to next handler
forward()
})
# logFilter is attached to router
router$addFilter(name="logger", expr=logFilter)
# defining a function, which would be used as an endpoint
fun_1 <- expression(function(...) {...})
# creating an endpoint at the router for fun_1
router$addEndpoint(verbs=c("POST"), path="/fun_1", expr = fun_1)
# plumbing an API at port 8000
router$run(port=8000)
我正在寻找的是一种捕获和记录管道工生成响应的内容和标题的方法。
我已尝试在端点之后立即实例化preemt-filter。但它似乎没有处理这个问题。
另外,我尝试将res变量传递给端点函数并从函数中调查它,如:
flog.info(paste0("res headers: ", res$headers), name = "mylogger")
但是,在这种情况下,标题为空。