The local source finds gems in the current directory for fulfilling dependencies.
A Lock
source wraps an installed gem’s source and sorts before other sources during dependency resolution. This allows RubyGems to prefer gems from dependency lock files.
The SpecFetcherSetup
allows easy setup of a remote source in RubyGems tests:
spec_fetcher do |f| f.gem 'a', 1 f.spec 'a', 2 f.gem 'b', 1' 'a' => '~> 1.0' end
The above declaration creates two gems, a-1 and b-1, with a dependency from b to a. The declaration creates an additional spec a-2, but no gem for it (so it cannot be installed).
After the gems are created they are removed from Gem.dir
.
RFC 2617 Digest
Access Authentication for WEBrick
Use this class to add digest authentication to a WEBrick
servlet.
Here is an example of how to set up DigestAuth:
config = { :Realm => 'DigestAuth example realm' } htdigest = WEBrick::HTTPAuth::Htdigest.new 'my_password_file' htdigest.set_passwd config[:Realm], 'username', 'password' htdigest.flush config[:UserDB] = htdigest digest_auth = WEBrick::HTTPAuth::DigestAuth.new config
When using this as with a servlet be sure not to create a new DigestAuth
object in the servlet’s initialize. By default WEBrick
creates a new servlet instance for every request and the DigestAuth
object must be used across requests.
Digest
authentication for proxy servers. See DigestAuth
for details.
Htdigest
accesses apache-compatible digest password files. Passwords are matched to a realm where they are valid. For security, the path for a digest password database should be stored outside of the paths available to the HTTP server.
Htdigest
is intended for use with WEBrick::HTTPAuth::DigestAuth
and stores passwords using cryptographic hashes.
htpasswd = WEBrick::HTTPAuth::Htdigest.new 'my_password_file' htpasswd.set_passwd 'my realm', 'username', 'password' htpasswd.flush
AbstractServlet
allows HTTP server modules to be reused across multiple servers and allows encapsulation of functionality.
By default a servlet will respond to GET, HEAD (through an alias to GET) and OPTIONS requests.
By default a new servlet is initialized for every request. A servlet instance can be reused by overriding ::get_instance
in the AbstractServlet
subclass.
class Simple < WEBrick::HTTPServlet::AbstractServlet def do_GET request, response status, content_type, body = do_stuff_with request response.status = status response['Content-Type'] = content_type response.body = body end def do_stuff_with request return 200, 'text/plain', 'you got a page' end end
This servlet can be mounted on a server at a given path:
server.mount '/simple', Simple
Servlets can be configured via initialize. The first argument is the HTTP server the servlet is being initialized for.
class Configurable < Simple def initialize server, color, size super server @color = color @size = size end def do_stuff_with request content = "<p " \ %q{style="color: #{@color}; font-size: #{@size}"} \ ">Hello, World!" return 200, "text/html", content end end
This servlet must be provided two arguments at mount time:
server.mount '/configurable', Configurable, 'red', '2em'
Servlet for handling CGI
scripts
Example:
server.mount('/cgi/my_script', WEBrick::HTTPServlet::CGIHandler, '/path/to/my_script')
Servlet for serving a single file. You probably want to use the FileHandler
servlet instead as it handles directories and fancy indexes.
Example:
server.mount('/my_page.txt', WEBrick::HTTPServlet::DefaultFileHandler, '/path/to/my_page.txt')
This servlet handles If-Modified-Since and Range
requests.
Serves a directory including fancy indexing and a variety of other options.
Example:
server.mount '/assets', WEBrick::FileHandler, '/path/to/assets'
Mounts a proc at a path that accepts a request and response.
Instead of mounting this servlet with WEBrick::HTTPServer#mount
use WEBrick::HTTPServer#mount_proc
:
server.mount_proc '/' do |req, res| res.body = 'it worked!' res.status = 200 end
Root of the HTTP error statuses
Root of the HTTP client error statuses
Class
used to manage timeout handlers across multiple threads.
Timeout
handlers should be managed by using the class methods which are synchronized.
id = TimeoutHandler.register(10, Timeout::Error) begin sleep 20 puts 'foo' ensure TimeoutHandler.cancel(id) end
will raise Timeout::Error
id = TimeoutHandler.register(10, Timeout::Error) begin sleep 5 puts 'foo' ensure TimeoutHandler.cancel(id) end
will print ‘foo’