Ruby Webrick HTTP Authentication

非 Y 不嫁゛ 提交于 2019-12-04 05:36:38

问题


How can I do the same authentication stuff in this page using a subclass like this:

        class Configuration < HTTPServlet::AbstractServlet
        def do_GET (request, response)
            SOMETHING....
        end
        end

    server = HTTPServer.new(:Port => 666)
    server.mount "/conf", Configuration
    trap "INT" do server.shutdown end
    server.start

回答1:


Seems to work OK for me if you do it in pretty much the same style e.g.

class Configuration < HTTPServlet::AbstractServlet
    def do_GET(req, res)
        HTTPAuth.basic_auth(req, res, "My Realm") {|user, pass|
          # block should return true if
          # authentication token is valid
          user == 'user' && pass == 'topsecret'
        }
        res.body = 
          "Authenticated OK\n"
    end
end

What is the problem you're having?



来源:https://stackoverflow.com/questions/1238272/ruby-webrick-http-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!