红宝石的WEBrick HTTP认证 [英] Ruby Webrick HTTP Authentication
本文介绍了红宝石的WEBrick HTTP认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能做到在此页面使用像这样的一个子类:
类配置和LT; HTTPServlet的:: AbstractServlet
高清do_GET(请求,响应)
SOMETHING ....
结束
结束 服务器= HTTPServer.new(:端口=> 666)
server.mount/ conf目录,配置
陷阱INT做server.shutdown结束
server.start
解决方案
看来,如果你在pretty这样做是为了工作确定对我来说同样款式例如
类配置和LT; HTTPServlet的:: AbstractServlet
高清do_GET(REQ,RES)
HTTPAuth.basic_auth(REQ,资源,我的王国){|用户,通过|
#块应该返回如果属实
#认证令牌是有效的
用户=='用户'和;&安培;通过=='绝密'
}
res.body =
认证OK \\ N
结束
结束
什么是你遇到的问题?
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
解决方案
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?
这篇关于红宝石的WEBrick HTTP认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文