summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-06-21 12:33:52 +0200
committerAzul <azul@riseup.net>2016-06-21 12:33:52 +0200
commitcd67dfac8f764140c47e0fba9304eba168c7a25b (patch)
treefb955e0ff28f53e8f05758936694844a8565156b /lib
parentb185742d959a0a3854c5e628354a538a15bdea15 (diff)
refactor: change send_response -> respond in em_server
This way the interface mimics the one of Celluloid Reels request. request.respond status, content
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver/em_server.rb8
-rw-r--r--lib/nickserver/request_handler.rb14
2 files changed, 9 insertions, 13 deletions
diff --git a/lib/nickserver/em_server.rb b/lib/nickserver/em_server.rb
index bcec4cd..a983249 100644
--- a/lib/nickserver/em_server.rb
+++ b/lib/nickserver/em_server.rb
@@ -23,11 +23,11 @@ module Nickserver
handler.respond_to params, @http_headers
end
- def send_response(options = {})
+ def respond(status, content)
response = EM::DelegatedHttpResponse.new(self)
- response.status = options[:status]
- response.content_type options[:content_type]
- response.content = options[:content]
+ response.status = status
+ response.content_type 'text/plain'
+ response.content = content
silence_warnings do
response.send_response
end
diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb
index 26b6ec1..a3fd57d 100644
--- a/lib/nickserver/request_handler.rb
+++ b/lib/nickserver/request_handler.rb
@@ -38,7 +38,7 @@ module Nickserver
source = Nickserver::Hkp::Source.new(adapter)
end
source.query(uid) do |response|
- send_response(status: response.status, content: response.content)
+ send_response response.status, response.content
end
end
@@ -64,19 +64,15 @@ module Nickserver
end
end
def send_error(msg = "not supported")
- send_response(status: 500, content: "500 #{msg}\n")
+ send_response 500, "500 #{msg}\n"
end
def send_not_found(msg = "Not Found")
- send_response(status: 404, content: "404 #{msg}\n")
+ send_response 404, "404 #{msg}\n"
end
- def send_response(opts = {})
- responder.send_response default_response.merge(opts)
- end
-
- def default_response
- {status: 200, content_type: 'text/plain', content: ''}
+ def send_response(status = 200, content = '')
+ responder.respond status, content
end
attr_reader :responder, :adapter