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::HTTPServlet::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’
An object representation of a stack frame, initialized by Kernel#caller_locations
.
For example:
# caller_locations.rb def a(skip) caller_locations(skip) end def b(skip) a(skip) end def c(skip) b(skip) end c(0..2).map do |call| puts call.to_s end
Running ruby caller_locations.rb
will produce:
caller_locations.rb:2:in `a' caller_locations.rb:5:in `b' caller_locations.rb:8:in `c'
Here’s another example with a slightly different result:
# foo.rb class Foo attr_accessor :locations def initialize(skip) @locations = caller_locations(skip) end end Foo.new(0..2).locations.map do |call| puts call.to_s end
Now run ruby foo.rb
and you should see:
init.rb:4:in `initialize' init.rb:8:in `new' init.rb:8:in `<main>'
The PersonConstruct
module is used to define a person Atom
element that can be used to describe a person, corporation or similar entity.
The PersonConstruct
has a Name
, Uri
and Email
child elements.
Reference: validator.w3.org/feed/docs/rfc4287.html#atomPersonConstruct
Gem::Resolver::Molinillo
is a generic dependency resolution algorithm.
Patterns used to parse URI’s