summaryrefslogtreecommitdiff
path: root/lib/nickserver/request_handler.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-08-27 09:09:07 +0200
committerAzul <azul@riseup.net>2016-08-27 09:09:07 +0200
commit47343fad827ac2bef2ed7bc08768e4e58ac9a95f (patch)
tree2d4645905ef0aec6546cb0934d0ef73ea9a1808a /lib/nickserver/request_handler.rb
parentdecdf85a8b2713fddf13888b48810d59b0ec2189 (diff)
refactor: push down adapter dependency injection to sources
The original idea was that we would have all the celluloid related things injected in reel_server. However it seems unlikely that we will use a different http system anytime soon. Removing some layers of dependency injection to reduce complexity. We can easily bring this back if we want.
Diffstat (limited to 'lib/nickserver/request_handler.rb')
-rw-r--r--lib/nickserver/request_handler.rb28
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb
index da9bcb3..239ac5f 100644
--- a/lib/nickserver/request_handler.rb
+++ b/lib/nickserver/request_handler.rb
@@ -33,9 +33,8 @@ module Nickserver
attr_reader :params, :headers
end
- def initialize(responder, adapter)
+ def initialize(responder)
@responder = responder
- @adapter = adapter
end
def respond_to(params, headers)
@@ -57,9 +56,9 @@ module Nickserver
def handler_for_request(request)
if request.email
- EmailHandler.new adapter
+ EmailHandler.new
elsif request.fingerprint
- FingerprintHandler.new adapter
+ FingerprintHandler.new
else
Proc.new { Nickserver::Response.new(404, "Not Found\n") }
end
@@ -67,10 +66,6 @@ module Nickserver
class EmailHandler
- def initialize(adapter)
- @adapter = adapter
- end
-
def call(request)
email = EmailAddress.new(request.email)
if email.invalid?
@@ -84,9 +79,9 @@ module Nickserver
def send_key(email, request)
if local_address?(email, request)
- source = Nickserver::CouchDB::Source.new(adapter)
+ source = Nickserver::CouchDB::Source.new
else
- source = Nickserver::Hkp::Source.new(adapter)
+ source = Nickserver::Hkp::Source.new
end
source.query(email)
rescue MissingHostHeader
@@ -102,29 +97,20 @@ module Nickserver
def local_address?(email, request)
email.domain?(Config.domain || request.domain)
end
-
- attr_reader :adapter
end
class FingerprintHandler
- def initialize(adapter)
- @adapter = adapter
- end
-
def call(request)
fingerprint = request.fingerprint
if fingerprint.length == 40 && !fingerprint[/\H/]
- source = Nickserver::Hkp::Source.new(adapter)
+ source = Nickserver::Hkp::Source.new
source.get_key_by_fingerprint(fingerprint)
else
ErrorResponse.new('Fingerprint invalid: ' + fingerprint)
end
end
- protected
-
- attr_reader :adapter
end
class ErrorResponse < Nickserver::Response
@@ -138,7 +124,7 @@ module Nickserver
responder.respond status, content
end
- attr_reader :responder, :adapter
+ attr_reader :responder
class MissingHostHeader < StandardError
end