summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-07 12:22:19 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-07 12:22:19 +0000
commit16291a0db719e9c174ab6890eb0c50ebef1cf8f7 (patch)
treed4ff408c0efe50815ed9c7d6561299a7a8a2c9f7
parentb33d3cfb41b459c7599486a5d5c7e45a4ce2a009 (diff)
* sample/webrick/*: new files.
* MANIFEST: add sample/webrick/* git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--MANIFEST8
-rw-r--r--sample/webrick/demo-app.rb66
-rw-r--r--sample/webrick/demo-multipart.cgi12
-rw-r--r--sample/webrick/demo-servlet.rb6
-rw-r--r--sample/webrick/demo-urlencoded.cgi12
-rw-r--r--sample/webrick/hello.cgi11
-rw-r--r--sample/webrick/hello.rb8
-rw-r--r--sample/webrick/httpd.rb23
-rw-r--r--sample/webrick/httpsd.rb33
10 files changed, 185 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ab62d919dd3..dcdf6b8b7f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jan 7 21:15:07 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * sample/webrick/*: new files.
+
+ * MANIFEST: add sample/webrick/*
+
Wed Jan 7 20:51:51 2004 Minero Aoki <aamine@loveruby.net>
* test/net/test_httpheader.rb: new file.
diff --git a/MANIFEST b/MANIFEST
index e4c13050eb2..336c7788fe5 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -663,6 +663,14 @@ sample/time.rb
sample/trojan.rb
sample/tsvr.rb
sample/uumerge.rb
+sample/webrick/demo-app.rb
+sample/webrick/demo-multipart.cgi
+sample/webrick/demo-servlet.rb
+sample/webrick/demo-urlencoded.cgi
+sample/webrick/hello.cgi
+sample/webrick/hello.rb
+sample/webrick/httpd.rb
+sample/webrick/httpsd.rb
sample/wsdl/amazon/AmazonSearch.rb
sample/wsdl/amazon/AmazonSearchDriver.rb
sample/wsdl/amazon/sampleClient.rb
diff --git a/sample/webrick/demo-app.rb b/sample/webrick/demo-app.rb
new file mode 100644
index 00000000000..c7a2a0a6a41
--- /dev/null
+++ b/sample/webrick/demo-app.rb
@@ -0,0 +1,66 @@
+require "pp"
+
+module DemoApplication
+ def initialize(config, enctype)
+ super
+ @enctype = enctype
+ end
+
+ def do_GET(req, res)
+ if req.path_info != "/"
+ res.set_redirect(WEBrick::HTTPStatus::Found, req.script_name + "/")
+ end
+ res.body =<<-_end_of_html_
+ <HTML>
+ <FORM method="POST" enctype=#{@enctype}>
+ text: <INPUT type="text" name="text"><BR>
+ file: <INPUT type="file" name="file"><BR>
+ check:
+ <INPUT type="checkbox" name="check" value="a">a,
+ <INPUT type="checkbox" name="check" value="b">b,
+ <INPUT type="checkbox" name="check" value="c">c,
+ <BR>
+ <INPUT type="submit">
+ </FORM>
+ </HTML>
+ _end_of_html_
+ res['content-type'] = 'text/html; charset=iso-8859-1'
+ end
+
+ def do_POST(req, res)
+ if req["content-length"].to_i > 1024*10
+ raise WEBrick::HTTPStatus::Forbidden, "file size too large"
+ end
+ res.body =<<-_end_of_html_
+ <HTML>
+ <H2>Query Parameters</H2>
+ #{display_query(req.query)}
+ <A href="#{req.path}">return</A>
+ <H2>Request</H2>
+ <PRE>#{WEBrick::HTMLUtils::escape(PP::pp(req, "", 80))}</PRE>
+ <H2>Response</H2>
+ <PRE>#{WEBrick::HTMLUtils::escape(PP::pp(res, "", 80))}</PRE>
+ </HTML>
+ _end_of_html_
+ res['content-type'] = 'text/html; charset=iso-8859-1'
+ end
+
+ private
+
+ def display_query(q)
+ ret = ""
+ q.each{|key, val|
+ ret << "<H3>#{WEBrick::HTMLUtils::escape(key)}</H3>"
+ ret << "<TABLE border=1>"
+ ret << make_tr("val", val.inspect)
+ ret << make_tr("val.to_a", val.to_a.inspect)
+ ret << make_tr("val.to_ary", val.to_ary.inspect)
+ ret << "</TABLE>"
+ }
+ ret
+ end
+
+ def make_tr(arg0, arg1)
+ "<TR><TD>#{arg0}</TD><TD>#{WEBrick::HTMLUtils::escape(arg1)}</TD></TR>"
+ end
+end
diff --git a/sample/webrick/demo-multipart.cgi b/sample/webrick/demo-multipart.cgi
new file mode 100644
index 00000000000..0893fadadfb
--- /dev/null
+++ b/sample/webrick/demo-multipart.cgi
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+require "webrick/cgi"
+require "webrick/https" # should load if it runs on HTTPS server
+require "./demo-app"
+
+class DemoCGI < WEBrick::CGI
+ include DemoApplication
+end
+
+config = { :NPH => false }
+cgi = DemoCGI.new(config, "multipart/form-data")
+cgi.start
diff --git a/sample/webrick/demo-servlet.rb b/sample/webrick/demo-servlet.rb
new file mode 100644
index 00000000000..9c18cc65d1e
--- /dev/null
+++ b/sample/webrick/demo-servlet.rb
@@ -0,0 +1,6 @@
+require "webrick"
+require "./demo-app"
+
+class DemoServlet < WEBrick::HTTPServlet::AbstractServlet
+ include DemoApplication
+end
diff --git a/sample/webrick/demo-urlencoded.cgi b/sample/webrick/demo-urlencoded.cgi
new file mode 100644
index 00000000000..e4706f8b598
--- /dev/null
+++ b/sample/webrick/demo-urlencoded.cgi
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+require "webrick/cgi"
+require "webrick/https" # should load if it runs on HTTPS server
+require "./demo-app"
+
+class DemoCGI < WEBrick::CGI
+ include DemoApplication
+end
+
+config = { :NPH => false }
+cgi = DemoCGI.new(config, "application/x-www-form-urlencoded")
+cgi.start
diff --git a/sample/webrick/hello.cgi b/sample/webrick/hello.cgi
new file mode 100644
index 00000000000..35d2240df0f
--- /dev/null
+++ b/sample/webrick/hello.cgi
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+require "webrick/cgi"
+
+class HelloCGI < WEBrick::CGI
+ def do_GET(req, res)
+ res["content-type"] = "text/plain"
+ res.body = "Hello, world.\n"
+ end
+end
+
+HelloCGI.new.start
diff --git a/sample/webrick/hello.rb b/sample/webrick/hello.rb
new file mode 100644
index 00000000000..4d026768182
--- /dev/null
+++ b/sample/webrick/hello.rb
@@ -0,0 +1,8 @@
+require "webrick"
+
+class HelloServlet < WEBrick::HTTPServlet::AbstractServlet
+ def do_GET(req, res)
+ res["content-type"] = "text/plain"
+ res.body = "Hello, world.\n"
+ end
+end
diff --git a/sample/webrick/httpd.rb b/sample/webrick/httpd.rb
new file mode 100644
index 00000000000..b0edf475825
--- /dev/null
+++ b/sample/webrick/httpd.rb
@@ -0,0 +1,23 @@
+require "webrick"
+
+httpd = WEBrick::HTTPServer.new(
+ :DocumentRoot => File::dirname(__FILE__),
+ :Port => 10080,
+ :Logger => WEBrick::Log.new($stderr, WEBrick::Log::DEBUG),
+ :AccessLog => [
+ [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
+ [ $stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
+ [ $stderr, WEBrick::AccessLog::AGENT_LOG_FORMAT ],
+ ],
+ :CGIPathEnv => ENV["PATH"] # PATH environment variable for CGI.
+)
+
+require "./hello"
+httpd.mount("/hello", HelloServlet)
+
+require "./demo-servlet"
+httpd.mount("/urlencoded", DemoServlet, "application/x-www-form-urlencoded")
+httpd.mount("/multipart", DemoServlet, "multipart/form-data")
+
+trap(:INT){ httpd.shutdown }
+httpd.start
diff --git a/sample/webrick/httpsd.rb b/sample/webrick/httpsd.rb
new file mode 100644
index 00000000000..9d82ef36cf1
--- /dev/null
+++ b/sample/webrick/httpsd.rb
@@ -0,0 +1,33 @@
+require "webrick"
+require "webrick/https"
+
+hostname = WEBrick::Utils::getservername
+subject = [["O", "ruby-lang.org"], ["OU", "sample"], ["CN", hostname]]
+comment = "Comment for self-signed certificate"
+
+httpd = WEBrick::HTTPServer.new(
+ :DocumentRoot => File::dirname(__FILE__),
+ :Port => 10443,
+ :SSLEnable => true,
+
+ # Specify key pair and server certificate.
+ # :SSLPrivateKey => OpenSSL::PKey::RSA.new("server.key"),
+ # :SSLCertificate => OpenSSL::X509::Certificate.new("server.crt"),
+
+ # specify the following SSL options if you want to use auto
+ # generated self-signed certificate.
+ :SSLCertName => subject,
+ :SSLComment => comment,
+
+ :CGIPathEnv => ENV["PATH"] # PATH environment variable for CGI.
+)
+
+require "./hello"
+httpd.mount("/hello", HelloServlet)
+
+require "./demo-servlet"
+httpd.mount("/urlencoded", DemoServlet, "application/x-www-form-urlencoded")
+httpd.mount("/multipart", DemoServlet, "multipart/form-data")
+
+trap(:INT){ httpd.shutdown }
+httpd.start