Sha256: 7cca44665575c865d4b013d5c584717d07275ddee97d366c7d9d2a5a3596dc37
Contents?: true
Size: 991 Bytes
Versions: 9
Compression:
Stored size: 991 Bytes
Contents
require 'webrick' require 'tempfile' class AuthServlet < WEBrick::HTTPServlet::AbstractServlet @instance = nil def self.get_instance server, *options @instance ||= new(server, *options) end def initialize server super server config = {} config[:Realm] = 'net-http-digest_auth' config[:UseOpaque] = false config[:AutoReloadUserDB] = false config[:Algorithm] = 'MD5' passwd_file = Tempfile.new 'net-http-digest_auth' passwd_file.close htpasswd = WEBrick::HTTPAuth::Htpasswd.new passwd_file.path htpasswd.auth_type = WEBrick::HTTPAuth::DigestAuth htpasswd.set_passwd config[:Realm], 'username', 'password' htpasswd.flush config[:UserDB] = htpasswd @digest_auth = WEBrick::HTTPAuth::DigestAuth.new config end def do_GET req, res @digest_auth.authenticate req, res res.body = 'worked!' end end s = WEBrick::HTTPServer.new :Port => 8000 s.mount '/', AuthServlet trap 'INT' do s.shutdown end s.start
Version data entries
9 entries across 9 versions & 3 rubygems