0
我查過了GitHub Repo和doc,但仍無法弄清楚如何在Plumber中獲取客戶端IP。如何在R Plumber中獲取客戶端IP地址
這裏是我試過的實施,我想爲所有的請求記錄到日誌文件添加IP地址,
#' @post /v1/rl
rl_v1 <- function(a, b, c){
request='rl'
start_time <- as.numeric(as.POSIXct(Sys.time()))
log_record <- paste(NULL, Sys.time(), request, "requested", NULL, NULL,
sep=",")
cat(paste(log_record, "\n", sep=""), file=log_file_name, append=T)
lhs <- data.frame(a=unlist(a),
b=unlist(b),
c=unlist(c))
pairs <- custom_function(lhs, rhs, m_w = 0.98,
ext_blk_field=c(12), international=T,
fasterWcoBlock=T, preprocessedData2=T)
input_records=nrow(lhs)
matches=nrow(pairs)
query_time <- as.numeric(as.POSIXct(Sys.time())) - start_time
status <- data.frame(query_time=query_time,
request=request,
type='POST',
api_version=api_version_v1)
log_record <- paste(NULL, Sys.time(), request, "responded",
round(matches/input_records*100, 2),
paste0(matches, '/', input_records, ' in ', query_time),
sep=",")
cat(paste(log_record, "\n", sep=""), file=log_file_name, append=T)
return(list(data=pairs, status=status))
}
任何幫助,高度讚賞。
你到底在說什麼?你在哪裏試圖獲得知識產權?請嘗試準備一個最小[可重現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),其中顯示了一些代碼,並描述了您需要。 – MrFlick
因爲'plumber'使用['httpuv'](https://github.com/rstudio/httpuv),所以你可以訪問['req $ REMOTE_ADDR'](https://github.com/rstudio/httpuv/search?utf8 =%E2%9C%93&q = remote_addr&type =)請求句柄的屬性。 – r2evans
謝謝@ r2evans工作... –