Skip to content

Instantly share code, notes, and snippets.

@treble37
Created September 4, 2012 21:46
Show Gist options
  • Save treble37/3626991 to your computer and use it in GitHub Desktop.
Save treble37/3626991 to your computer and use it in GitHub Desktop.
Webrick meets rvm meets curb
##NOTE: /myproject is my abbreviated name for /home/bruce/Desktop/github_projects/rsocialize
$ ruby wserver.rb
[2012-09-04 17:52:44] INFO WEBrick 1.3.1
[2012-09-04 17:52:44] INFO ruby 1.9.3 (2012-04-20) [i686-linux]
[2012-09-04 17:52:44] WARN TCPServer Error: Address already in use - bind(2)
[2012-09-04 17:52:44] INFO WEBrick::HTTPServer#start: pid=4430 port=3000
[2012-09-04 17:52:47] ERROR CGIHandler: /home/bruce/Desktop/github_projects/rsocialize/lib/html/ruby_cgi_post.cgi:
/home/bruce/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpservlet/cgi_runner.rb:46:in `exec': No such file or directory - /home/bruce/Desktop/github_projects/rsocialize/lib/html/ruby_cgi_post.cgi (Errno::ENOENT)
from /home/bruce/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpservlet/cgi_runner.rb:46:in `<main>'
[2012-09-04 17:52:47] ERROR CGIHandler: /home/bruce/Desktop/github_projects/rsocialize/lib/html/ruby_cgi_post.cgi exit with 1
[2012-09-04 17:52:47] ERROR Premature end of script headers: /home/bruce/Desktop/github_projects/rsocialize/lib/html/ruby_cgi_post.cgi
localhost - - [04/Sep/2012:17:52:47 EDT] "POST /ruby_cgi_post.cgi HTTP/1.1" 500 386
http://localhost:3000/ -> /ruby_cgi_post.cgi
cd to /myproject/lib
> ruby wserver.rb
#Next I fire up a webrowser and point to http://localhost:3000/
Then I submit the form with an url (yahoo.com) and text parameter (googlePlus).
Then the cgi script throws an error.
<!--located in /myproject/lib/html -->
<html><head></head><body>
<p>Two example HTML forms for testing Ruby CGI scripts</p>
<hr>
<p>Form with (method="post")</p>
<form action="ruby_cgi_post.cgi" method="post">
Enter Value: <input type="text" name="url" value="http://www.yahoo.com/"><br/>
Enter Value: <input type="text" name="type" value="googlePlus"><br/>
<input type="submit">
</form>
<br/>
<hr>
</body></html>
#!/home/bruce/.rvm/wrappers/ruby-1.9.3-p194@rsoc326/bin/ruby
## /home/bruce/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
## <!--located in /myproject/lib/html -->
require 'rubygems'
require 'cgi'
require 'net/http'
require 'curb'
params = CGI.new
@url = CGI::escape(params['url']);
@type = CGI::escape(params['type']);
print "Content-type: text/plain\n\n"
print "Hello: #{@url}\n"
#!/home/bruce/.rvm/wrappers/ruby-1.9.3-p194@rsoc326/bin/ruby
require 'rubygems'
require 'cgi'
require 'net/http'
#require 'curb'
params = CGI.new
@url = CGI::escape(params['url']);
@type = CGI::escape(params['type']);
print "Content-type: text/plain\n\n"
print "Hello: #{@url}\n"
#!/home/bruce/.rvm/wrappers/ruby-1.9.3-p194@rsoc326/bin/ruby
require 'rubygems'
require 'cgi'
require 'net/http'
#require 'curb'
params = CGI.new
@url = CGI::escape(params['url']);
@type = CGI::escape(params['type']);
print "Content-type: text/plain\n\n"
print "Hello: #{@url}\n"
#!/home/bruce/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
require 'rubygems'
require 'cgi'
require 'net/http'
#require 'curb'
params = CGI.new
@url = CGI::escape(params['url']);
@type = CGI::escape(params['type']);
print "Content-type: text/plain\n\n"
print "Hello: #{@url}\n"
#located in directory /myproject/lib
require 'webrick'
include WEBrick
s = HTTPServer.new(
:Port => 3000,
:DocumentRoot => File.join(Dir.pwd, "/html")
)
trap("INT") { s.shutdown }
s.start
#Dir.pwd => home/bruce/Desktop/github_projects/rsocialize/lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment