about summary refs log tree commit homepage
path: root/examples/webrick_compare.rb
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webrick_compare.rb')
-rw-r--r--examples/webrick_compare.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/webrick_compare.rb b/examples/webrick_compare.rb
new file mode 100644
index 0000000..15199b0
--- /dev/null
+++ b/examples/webrick_compare.rb
@@ -0,0 +1,20 @@
+#!/usr/local/bin/ruby
+require 'webrick'
+include WEBrick
+
+s = HTTPServer.new( :Port => 4000 )
+
+# HTTPServer#mount(path, servletclass)
+#   When a request referring "/hello" is received,
+#   the HTTPServer get an instance of servletclass
+#   and then call a method named do_"a HTTP method".
+
+class HelloServlet < HTTPServlet::AbstractServlet
+  def do_GET(req, res)
+    res.body = "hello!"
+    res['Content-Type'] = "text/html"
+  end
+end
+s.mount("/test", HelloServlet)
+
+s.start \ No newline at end of file