jeffreyhorner / Rook

A web server interface for R
161 stars 30 forks source link

Odd failure with 127.0.0.1, works with localhost #19

Closed hughjonesd closed 10 years ago

hughjonesd commented 10 years ago

Run the code below. Type something into the text box and submit the form.

For me, the form parameter is submitted correctly when the URL is "localhost". But it is not submitted when the URL is "127.0.0.1". Instead, I only get the GET parameters from the query string.

My R version: 3.0.2. Rook version: 1.0-9.

library(Rook)
ls_str <- function(s) paste(capture.output(str(s),file=NULL),collapse='\n')

s <- Rhttpd$new()
## End(Not run)
s$add(name="request",
  app=function(env){
    req <- Request$new(env)
    res <- Response$new()
    res$set_cookie('imacookie','42')
    action <- req$to_url('/foo',bar=1,baz='three')
    res$write('<form enctype="multipart/form-data" method=POST action="')
    res$write(action)
    res$write('">')
    res$write("<input type='text' name='somename' value='enter something here'>")
    res$write('<input type=submit></form><br><pre>')
res$write("what are my params???")
res$write(ls_str(req$params()))
res$write("\n\n\n\n\n")
res$write("Works with localhost, but not with 127.0.0.1")

res$write(c('parseable_data: ',req$parseable_data(),'\n'))
    res$write(c('url: ',req$url(),'\n'))
    res$write(c('request_method: ',req$request_method(),'\n'))
    res$write(c('GET: ',ls_str(req$GET()),'\n'))
    res$write(c('post: ',req$post(),'\n'))
    res$write(c('media_type: ',req$media_type(),'\n'))
    res$write(c('query_string: ',req$query_string(),'\n'))
    res$write(c('fullpath: ',req$fullpath(),'\n'))
    res$write(c('referer: ',req$referer(),'\n'))
    res$write(c('cookies: ',ls_str(req$cookies()),'\n'))
    res$write(c('content_charset: ',req$content_charset(),'\n'))
    res$write(c('head: ',req$head(),'\n'))
    res$write(c('accept_encoding: ',req$accept_encoding(),'\n'))
    res$write(c('content_length: ',req$content_length(),'\n'))
    res$write(c('form_data: ',req$form_data(),'\n'))
    res$write(c('xhr: ',req$xhr(),'\n'))
    res$write(c('params: ',ls_str(req$params()),'\n'))
    res$write(c('media_type_params:\n',ls_str(req$media_type_params()),'\n'))
    res$write(c('user_agent: ',req$user_agent(),'\n'))
    res$write(c('put: ',req$put(),'\n'))
    res$write(c('get: ',req$get(),'\n'))
    res$write(c('path: ',req$path(),'\n'))
    res$write(c('body: ',ls_str(req$body()),'\n'))
    res$write(c('port: ',req$port(),'\n'))
    res$write(c('host_with_port: ',req$host_with_port(),'\n'))
    res$write(c('scheme: ',req$scheme(),'\n'))
    res$write(c('ip: ',req$ip(),'\n'))
    res$write(c('options: ',req$options(),'\n'))
    res$write(c('to_url: ',req$to_url('foo',bar=1,baz='two'),'\n'))
    res$write(c('host: ',req$host(),'\n'))
    res$write(c('POST: ',ls_str(req$POST()),'\n'))
    res$write(c('trace: ',req$trace(),'\n'))
    res$write(c('script_name: ',req$script_name(),'\n'))
    res$write(c('content_type: ',req$content_type(),'\n'))
    res$write(c('delete: ',req$delete(),'\n'))
    res$write(c('path_info: ',req$path_info(),'\n'))
    res$write(c('\nRac env: ',ls_str(as.list(env)),'\n'))
    res$finish()
  }
)

s$start(quiet=TRUE)
jeffreyhorner commented 10 years ago

This is really a machine specific issue. I would recommend fixing it on your machine. From the startDynamicHelp page:

The browser in use does need to be able to connect to the loopback
 interface: occasionally it is set to use a proxy for HTTP on all
 interfaces, which will not work - the solution is to add an
 exception for ‘127.0.0.1’.