U:RDoc::NormalModule[iI" WEBrick:EF@0o:RDoc::Markup::Document: @parts[&o;;[lS:RDoc::Markup::Heading: leveli: textI"WEB server toolkit.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Paragraph;[ I"RWEBrick is an HTTP server toolkit that can be configured as an HTTPS server, ;TI"Ka proxy server, and a virtual-host server. WEBrick features complete ;TI"Ologging of both server operations and HTTP access. WEBrick supports both ;TI"Obasic and digest authentication in addition to algorithms not in RFC 2617.;T@o; ;[ I"QA WEBrick server can be composed of multiple WEBrick servers or servlets to ;TI"Jprovide differing behavior on a per-host or per-path basis. WEBrick ;TI"Lincludes servlets for handling CGI scripts, ERB pages, Ruby blocks and ;TI"directory listings.;T@o; ;[I"RWEBrick also includes tools for daemonizing a process and starting a process ;TI":at a higher privilege level and dropping permissions.;T@S; ; i; I"Starting an HTTP server;T@o; ;[I"QTo create a new WEBrick::HTTPServer that will listen to connections on port ;TI"I8000 and serve documents from the current user's public_html folder:;T@o:RDoc::Markup::Verbatim;[ I"require 'webrick' ;TI" ;TI"-root = File.expand_path '~/public_html' ;TI"Kserver = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root ;T: @format0o; ;[I"LTo run the server you will need to provide a suitable shutdown hook as ;TI"3starting the server blocks the current thread:;T@o;;[I"'trap 'INT' do server.shutdown end ;TI" ;TI"server.start ;T;0S; ; i; I"Custom Behavior;T@o; ;[ I"KThe easiest way to have a server perform custom operations is through ;TI"LWEBrick::HTTPServer#mount_proc. The block given will be called with a ;TI"NWEBrick::HTTPRequest with request info and a WEBrick::HTTPResponse which ;TI"%must be filled in appropriately:;T@o;;[I")server.mount_proc '/' do |req, res| ;TI"" res.body = 'Hello, world!' ;TI" end ;T;0o; ;[I"CRemember that +server.mount_proc+ must precede +server.start+.;T@S; ; i; I" Servlets;T@o; ;[ I"MAdvanced custom behavior can be obtained through mounting a subclass of ;TI"NWEBrick::HTTPServlet::AbstractServlet. Servlets provide more modularity ;TI"Kwhen writing an HTTP server than mount_proc allows. Here is a simple ;TI" servlet:;T@o;;[I":class Simple < WEBrick::HTTPServlet::AbstractServlet ;TI"$ def do_GET request, response ;TI"< status, content_type, body = do_stuff_with request ;TI" ;TI" response.status = 200 ;TI"1 response['Content-Type'] = 'text/plain' ;TI") response.body = 'Hello, World!' ;TI" end ;TI" end ;T;0o; ;[I":To initialize the servlet you mount it on the server:;T@o;;[I"$server.mount '/simple', Simple ;T;0o; ;[I"@See WEBrick::HTTPServlet::AbstractServlet for more details.;T@S; ; i; I"Virtual Hosts;T@o; ;[I"QA server can act as a virtual host for multiple host names. After creating ;TI"Pthe listening host, additional hosts that do not listen can be created and ;TI"attached as virtual hosts:;T@o;;[ I",server = WEBrick::HTTPServer.new # ... ;TI" ;TI"Evhost = WEBrick::HTTPServer.new :ServerName => 'vhost.example', ;TI"A :DoNotListen => true, # ... ;TI"vhost.mount '/', ... ;TI" ;TI"server.virtual_host vhost ;T;0o; ;[I"SIf no +:DocumentRoot+ is provided and no servlets or procs are mounted on the ;TI"1main server it will return 404 for all URLs.;T@S; ; i; I" HTTPS;T@o; ;[I"NTo create an HTTPS server you only need to enable SSL and provide an SSL ;TI"certificate name:;T@o;;[I"require 'webrick' ;TI"require 'webrick/https' ;TI" ;TI"cert_name = [ ;TI" %w[CN localhost], ;TI"] ;TI" ;TI"5server = WEBrick::HTTPServer.new(:Port => 8000, ;TI": :SSLEnable => true, ;TI"A :SSLCertName => cert_name) ;T;0o; ;[I"OThis will start the server with a self-generated self-signed certificate. ;TI"HThe certificate will be changed every time the server is restarted.;T@o; ;[I"RTo create a server with a pre-determined key and certificate you can provide ;TI" them:;T@o;;[I"require 'webrick' ;TI"require 'webrick/https' ;TI"require 'openssl' ;TI" ;TI"Icert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem' ;TI"Apkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem' ;TI" ;TI"5server = WEBrick::HTTPServer.new(:Port => 8000, ;TI": :SSLEnable => true, ;TI"? :SSLCertificate => cert, ;TI"> :SSLPrivateKey => pkey) ;T;0S; ; i; I"Proxy Server;T@o; ;[I"'WEBrick can act as a proxy server:;T@o;;[ I"require 'webrick' ;TI"!require 'webrick/httpproxy' ;TI" ;TI"8proxy = WEBrick::HTTPProxyServer.new :Port => 8000 ;TI" ;TI"&trap 'INT' do proxy.shutdown end ;T;0o; ;[I"LSee WEBrick::HTTPProxy for further details including modifying proxied ;TI"responses.;T@S; ; i; I"$Basic and Digest authentication;T@o; ;[I"QWEBrick provides both Basic and Digest authentication for regular and proxy ;TI"Gservers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and ;TI"#WEBrick::HTTPAuth::DigestAuth.;T@S; ; i; I"'WEBrick as a Production Web Server;T@o; ;[I"?WEBrick can be run as a production server for small loads.;T@S; ; i; I"Daemonizing;T@o; ;[I"LTo start a WEBrick server as a daemon simple run WEBrick::Daemon.start ;TI" before starting the server.;T@S; ; i; I"Dropping Permissions;T@o; ;[I"QWEBrick can be started as one user to gain permission to bind to port 80 or ;TI"O443 for serving HTTP or HTTPS traffic then can drop these permissions for ;TI"Fregular operation. To listen on all interfaces for HTTP traffic:;T@o;;[I"7sockets = WEBrick::Utils.create_listeners nil, 80 ;T;0o; ;[I"Then drop privileges:;T@o;;[I"WEBrick::Utils.su 'www' ;T;0o; ;[I":Then create a server that does not listen by default:;T@o;;[I"Bserver = WEBrick::HTTPServer.new :DoNotListen => true, # ... ;T;0o; ;[I"CThen overwrite the listening sockets with the port 80 sockets:;T@o;;[I"&server.listeners.replace sockets ;T;0S; ; i; I" Logging;T@o; ;[I"LWEBrick can separately log server operations and end-user access. For ;TI"server operations:;T@o;;[I"7log_file = File.open '/var/log/webrick.log', 'a+' ;TI"%log = WEBrick::Log.new log_file ;T;0o; ;[I"For user access logging:;T@o;;[ I"access_log = [ ;TI"< [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT], ;TI"] ;TI" ;TI"Oserver = WEBrick::HTTPServer.new :Logger => log, :AccessLog => access_log ;T;0o; ;[I"4See WEBrick::AccessLog for further log formats.;T@S; ; i; I"Log Rotation;T@o; ;[I"QTo rotate logs in WEBrick on a HUP signal (like syslogd can send), open the ;TI"Llog file in 'a+' mode (as above) and trap 'HUP' to reopen the log file:;T@o;;[I"@trap 'HUP' do log_file.reopen '/path/to/webrick.log', 'a+' ;T;0S; ; i; I"Copyright;T@o; ;[I"=Author: IPR -- Internet Programming with Ruby -- writers;T@o; ;[I":Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU ;TI"KCopyright (c) 2002 Internet Programming with Ruby writers. All rights ;TI"reserved.;T: @fileI"lib/webrick.rb;T:0@omit_headings_from_table_of_contents_below0o;;[;I"lib/webrick/accesslog.rb;T;0o;;[;I"lib/webrick/cgi.rb;T;0o;;[;I"lib/webrick/config.rb;T;0o;;[;I"lib/webrick/cookie.rb;T;0o;;[;I"lib/webrick/htmlutils.rb;T;0o;;[;I"lib/webrick/httpauth.rb;T;0o;;[;I"*lib/webrick/httpauth/authenticator.rb;T;0o;;[;I"&lib/webrick/httpauth/basicauth.rb;T;0o;;[;I"'lib/webrick/httpauth/digestauth.rb;T;0o;;[;I"%lib/webrick/httpauth/htdigest.rb;T;0o;;[;I"$lib/webrick/httpauth/htgroup.rb;T;0o;;[;I"%lib/webrick/httpauth/htpasswd.rb;T;0o;;[;I"#lib/webrick/httpauth/userdb.rb;T;0o;;[;I"lib/webrick/httpproxy.rb;T;0o;;[;I"lib/webrick/httprequest.rb;T;0o;;[;I" lib/webrick/httpresponse.rb;T;0o;;[;I"lib/webrick/https.rb;T;0o;;[;I"lib/webrick/httpserver.rb;T;0o;;[;I"lib/webrick/httpservlet.rb;T;0o;;[;I"(lib/webrick/httpservlet/abstract.rb;T;0o;;[;I"*lib/webrick/httpservlet/cgihandler.rb;T;0o;;[;I"*lib/webrick/httpservlet/erbhandler.rb;T;0o;;[;I"+lib/webrick/httpservlet/filehandler.rb;T;0o;;[;I"+lib/webrick/httpservlet/prochandler.rb;T;0o;;[;I"lib/webrick/httpstatus.rb;T;0o;;[;I"lib/webrick/httputils.rb;T;0o;;[;I"lib/webrick/httpversion.rb;T;0o;;[;I"lib/webrick/log.rb;T;0o;;[;I"lib/webrick/server.rb;T;0o;;[;I"lib/webrick/ssl.rb;T;0o;;[;I"lib/webrick/utils.rb;T;0o;;[;I"lib/webrick/version.rb;T;0;0;0[[U:RDoc::Constant[iI" VERSION;FI"WEBrick::VERSION;T00o;;[o; ;[I"The WEBrick version;T;@_;0@_@cRDoc::NormalModule0[[[I" class;T[[: public[[:protected[[: private[[I" instance;T[[;[ [I" cancel;FI"lib/webrick/utils.rb;T[I"interrupt;F@~[I" register;F@~[I"terminate;F@~[;[[;[[[U:RDoc::Context::Section[i0o;;[;0;0[&@ÿ@@@@ @@@@@@@ @#@&@)@,@/@2@5@8@;@>@A@D@G@J@M@P@S@V@Y@\@_@_cRDoc::TopLevel