File: server.rb

package info (click to toggle)
ruby-em-http-request 1.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 680 kB
  • sloc: ruby: 4,011; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'webrick'

include WEBrick

config = { :Realm => 'DigestAuth_REALM' }

htdigest = WEBrick::HTTPAuth::Htdigest.new 'my_password_file'
htdigest.set_passwd config[:Realm], 'digest_username', 'digest_password'
htdigest.flush

config[:UserDB] = htdigest

digest_auth = WEBrick::HTTPAuth::DigestAuth.new config

class TestServlet < HTTPServlet::AbstractServlet
  def do_GET(req, res)
    @options[0][:authenticator].authenticate req, res
    res.body = "You are authenticated to see the super secret data\n"
  end
end

s = HTTPServer.new(:Port => 3000)
s.mount('/', TestServlet, {:authenticator => digest_auth})
trap("INT") do
  File.delete('my_password_file')
  s.shutdown
end
s.start