summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-08-27 11:25:30 +0200
committerAzul <azul@riseup.net>2016-08-29 08:59:58 +0200
commit16d77cc03068b19791e704abfc2eb14f8cd141f0 (patch)
treea6d5f0b6fbe32fed887d9506150b1082297d49d8 /lib
parent47343fad827ac2bef2ed7bc08768e4e58ac9a95f (diff)
expose Request class from RequestHandler
This way we can separate the EmailHandler and the FingerprintHandler as well.
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver/request.rb30
-rw-r--r--lib/nickserver/request_handler.rb36
2 files changed, 35 insertions, 31 deletions
diff --git a/lib/nickserver/request.rb b/lib/nickserver/request.rb
new file mode 100644
index 0000000..c21c280
--- /dev/null
+++ b/lib/nickserver/request.rb
@@ -0,0 +1,30 @@
+module Nickserver
+ class Request
+ def initialize(params, headers)
+ @params = params || {}
+ @headers = headers
+ end
+
+ def email
+ param("address")
+ end
+
+ def fingerprint
+ param("fingerprint")
+ end
+
+ def domain
+ host_header = headers['Host'] || ''
+ domain_part = host_header.split(':')[0] || ''
+ domain_part.strip.sub(/^nicknym\./, '')
+ end
+
+ protected
+
+ def param(key)
+ params[key] && params[key].first
+ end
+
+ attr_reader :params, :headers
+ end
+end
diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb
index 239ac5f..1239c44 100644
--- a/lib/nickserver/request_handler.rb
+++ b/lib/nickserver/request_handler.rb
@@ -1,44 +1,16 @@
require 'nickserver/hkp/source'
require 'nickserver/couch_db/source'
+require 'nickserver/request'
module Nickserver
class RequestHandler
- class Request
- def initialize(params, headers)
- @params = params || {}
- @headers = headers
- end
-
- def email
- param("address")
- end
-
- def fingerprint
- param("fingerprint")
- end
-
- def domain
- host_header = headers['Host']
- raise MissingHostHeader if host_header.nil?
- host_header.split(':')[0].strip.sub(/^nicknym\./, '')
- end
-
- protected
-
- def param(key)
- params[key] && params[key].first
- end
-
- attr_reader :params, :headers
- end
-
def initialize(responder)
@responder = responder
end
def respond_to(params, headers)
- request = Request.new params, headers
+ request = Nickserver::Request.new params, headers
response = handle request
send_response response.status, response.content
end
@@ -95,7 +67,9 @@ module Nickserver
# If 'domain' is not configured, we rely on the Host header of the HTTP request.
#
def local_address?(email, request)
- email.domain?(Config.domain || request.domain)
+ domain = Config.domain || request.domain
+ raise MissingHostHeader if domain == ''
+ email.domain? domain
end
end