Hello,

Would it be possible to include the body of the request that is sent to the internal web server as the "body" argument of the httpd function ?

At the moment, in Rhttpd.c the body is filled as part of the worker_input_handler, but it does not arrive to the R side (the httpd function).

I'm attaching a small patch that adds a "body" argument to httpd and sets it to either NULL when there is no body or the body, as a raw vector.

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/FtUu : new package : highlight
|- http://tr.im/EAD5 : LondonR slides
`- http://tr.im/BcPw : celebrating R commit #50000

Index: src/library/tools/R/dynamicHelp.R
===================================================================
--- src/library/tools/R/dynamicHelp.R   (revision 50616)
+++ src/library/tools/R/dynamicHelp.R   (working copy)
@@ -21,7 +21,7 @@
 ##  documentation with path = "/doc/....", possibly updated under tempdir()/.R
 ##  html help, either by topic, /library/<pkg>/help/<topic> (pkg=NULL means 
any)
 ##             or by file, /library/<pkg>/html/<file>.html
-httpd <- function(path, query, ...)
+httpd <- function(path, query, body, ...)
 {
     .HTMLdirListing <- function(dir, base, up)
     {
Index: src/modules/internet/Rhttpd.c
===================================================================
--- src/modules/internet/Rhttpd.c       (revision 50616)
+++ src/modules/internet/Rhttpd.c       (working copy)
@@ -406,6 +406,22 @@
        c->attr |= CONNECTION_CLOSE;
 }
 
+/*
+ * structures the body as a raw vector if there is a body or return NULL 
+ * otherwise
+ */
+static SEXP parse_body(httpd_conn_t *c) {
+       char* body = c->body ;
+       /* no body */
+       if( !body ) return R_NilValue ;
+       
+       /* structure the body as a raw vector */
+       SEXP res = PROTECT( Rf_allocVector( RAWSXP, c->content_length ) );
+       memcpy( RAW(res), c->body, c->content_length ) ;
+       UNPROTECT( 1 ) ; /* res */
+       return res ;
+}
+
 /* process a request by calling the httpd() function in R */
 static void process_request(httpd_conn_t *c)
 {
@@ -424,7 +440,7 @@
     uri_decode(c->url); /* decode the path part */
     { /* construct try(httpd(url, query), silent=TRUE) */
        SEXP sTrue = PROTECT(ScalarLogical(TRUE));
-       SEXP y, x = PROTECT(lang3(install("try"), LCONS(install("httpd"), 
CONS(mkString(c->url), CONS(query ? parse_query(query) : R_NilValue, 
R_NilValue))), sTrue));
+       SEXP y, x = PROTECT(lang3(install("try"), LCONS(install("httpd"), 
CONS(mkString(c->url), CONS(query ? parse_query(query) : R_NilValue, 
CONS(parse_body(c),R_NilValue)))), sTrue));
        SET_TAG(CDR(CDR(x)), install("silent"));
        DBG(Rprintf("eval(try(httpd('%s'),silent=TRUE))\n", c->url));
        x = PROTECT(eval(x, R_FindNamespace(mkString("tools"))));
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to