1

I'm trying to set up nginx directly in front of Rserve (HTTP). The Rserve 1.7.0 release notes (http://www.rforge.net/Rserve/news.html) suggest that you need to define the .http.request worker function. Every example I've come across suggests adding these lines to Rserv.conf, but I don't want to use FastRWeb.

library(FastRWeb)
.http.request <- FastRWeb:::.http.request

My Rserve.conf as-is:

remote enable http.port 6312

Can you help me with an implementation of .http.request that doesn't depend on FastRWeb? Thanks!

1 Answers1

2

I'm not sure I understand how this is related to nginx since that would be only acting as reverse-proxy and thus requires no changes to the Rserve configuration.

But .http.request has to be simply a function defined as

.http.request <- function(url, query, body, headers, ...)

You can do whatever you want and then return the following (quoted from Rserve):

       the result is expected to have one of the following forms:             

       a) character vector of length 1 => error (possibly from try),          
       will create 500 response                                               

       b) list(payload[, content-type[, headers[, status code]]])             

       payload: can be a character vector of length one or a                  
       raw vector. if the character vector is named "file" then               
       the content of a file of that name is the payload                      

       content-type: must be a character vector of length one                 
       or NULL (if present, else default is "text/html")                      

       headers: must be a character vector - the elements will                
       have CRLF appended and neither Content-type nor                        
       Content-length may be used                                             

       status code: must be an integer if present (default is 200)            

Only payload is mandatory, everything else is optional. It is a good idea to wrap your code in something like tryCatch({ ... }, error=function(e) e$message) so you see the output in case of a failure.

Note that this is the same API as used by the built-in HTTP server in R.

PS: Please consider using the stats-rosuda-devel mailing list for Rserve-related questions.

Simon Urbanek
  • 13,842
  • 45
  • 45