summaryrefslogtreecommitdiff
path: root/lib/nickserver
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-09-22 11:07:47 +0200
committerAzul <azul@riseup.net>2016-09-22 11:07:47 +0200
commit48cdd4b1ee0685674aa998d4daa295656d80ead3 (patch)
tree7303cb6490c75e1836cc790c62a58f58e820a703 /lib/nickserver
parente1a78d46298d556b09bfcac0fa797b8e32b965d4 (diff)
feature: 502 on ConnectionErrors
If one source raises a 502 and no other handler has any result we'll respond with a 502 - bad gateway.
Diffstat (limited to 'lib/nickserver')
-rw-r--r--lib/nickserver/dispatcher.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb
index 75f6083..869f721 100644
--- a/lib/nickserver/dispatcher.rb
+++ b/lib/nickserver/dispatcher.rb
@@ -24,6 +24,7 @@ require 'nickserver/request_handlers/fingerprint_handler'
module Nickserver
class Dispatcher
+
def initialize(responder)
@responder = responder
end
@@ -45,12 +46,26 @@ module Nickserver
end
def handler_chain
- HandlerChain.new RequestHandlers::InvalidEmailHandler,
+ @handler_chain ||= init_handler_chain
+ end
+
+ def init_handler_chain
+ chain = HandlerChain.new RequestHandlers::InvalidEmailHandler,
RequestHandlers::LocalEmailHandler,
RequestHandlers::LeapEmailHandler,
RequestHandlers::HkpEmailHandler,
RequestHandlers::FingerprintHandler,
+ Proc.new {|_req| proxy_error_response },
Proc.new { Nickserver::Response.new(404, "404 Not Found\n") }
+ chain.continue_on HTTP::ConnectionError
+ return chain
+ end
+
+ def proxy_error_response
+ exception = handler_chain.rescued_exceptions.first
+ if exception
+ Nickserver::Response.new(502, exception.to_s)
+ end
end
def send_response(response)