diff options
author | elijah <elijah@riseup.net> | 2012-12-24 16:25:39 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2012-12-24 16:25:39 -0800 |
commit | 8a70059fed66daa00dd9f8558748255735c91846 (patch) | |
tree | 47d22bb1719d389f4c1cc9b3a91d7cdb94fdee84 /lib | |
parent | 8b5cd59867b00829dfe9d38531d44f1fdf4edbdc (diff) |
added nickserver daemon
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/server.rb | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/nickserver/server.rb b/lib/nickserver/server.rb index 4201cef..21975d4 100644 --- a/lib/nickserver/server.rb +++ b/lib/nickserver/server.rb @@ -1,31 +1,36 @@ require 'eventmachine' require 'evma_httpserver' - # # This is the main HTTP server that clients connect to in order to fetch keys # +# For now, its API is very simple: +# +# GET /keys/<uid> --> returns OpenPGP key for uid. +# module Nickserver class Server < EM::Connection include EM::HttpServer + # + # Starts the Nickserver. Must be run inside an EM.run block. + # + # Available options: + # + # * :port (default Nickserver::Config.port) + # * :host (default 0.0.0.0) + # + def self.start(opts={}) + options = {:host => '0.0.0.0', :port => Nickserver::Config.port}.merge(opts) + EM.start_server options[:host], options[:port], Nickserver::Server + end + def post_init super no_environment_strings end def process_http_request - # the http request details are available via the following instance variables: - # @http_protocol - # @http_request_method - # @http_cookie - # @http_if_none_match - # @http_content_type - # @http_path_info - # @http_request_uri - # @http_query_string - # @http_post_content - # @http_headers if @http_request_method == "GET" if @http_path_info =~ /^\/key\// send_key @@ -43,13 +48,6 @@ module Nickserver send_response(:status => 500, :content => msg) end - def send_key - uid = CGI.unescape @http_path_info.sub(/^\/key\/(.*)/, '\1') - get_key_from_uid(uid) do |key| - send_response(:content => key) - end - end - def send_response(opts = {}) options = {:status => 200, :content_type => 'text/plain', :content => ''}.merge(opts) response = EM::DelegatedHttpResponse.new(self) @@ -59,6 +57,13 @@ module Nickserver response.send_response end + def send_key + uid = CGI.unescape @http_path_info.sub(/^\/key\/(.*)/, '\1') + get_key_from_uid(uid) do |key| + send_response(:content => key) + end + end + def get_key_from_uid(uid) Nickserver::HKP::FetchKey.new.get(uid).callback {|key| yield key |