Created
January 15, 2012 18:27
-
-
Save ruprict/1616686 to your computer and use it in GitHub Desktop.
SimpleAroundAware issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'goliath' | |
class ApiValidationAroundware | |
include Goliath::Rack::SimpleAroundware | |
class InvalidApiKeyError < Goliath::Validation::BadRequestError; end | |
def pre_process | |
validate_api_key! | |
env.logger.info "past api_key validation" #<-- this is output, then an empty response header & body as if it is just hanging... | |
Goliath::Connection::AsyncResponse | |
end | |
def post_process | |
[status, headers, body] | |
end | |
def validate_api_key! | |
server_api_key = env['config']['server_api_key'].to_s | |
if api_key != server_api_key | |
raise InvalidApiKeyError | |
end | |
end | |
# retreive the client's api_key | |
def api_key | |
env['HTTP_API_KEY'].to_s | |
end | |
end | |
class Version < Goliath::API | |
def response(env) | |
[200, {"Content-Type" => "text/html"}, ["Version 0.1"]] | |
end | |
end | |
class Test < Goliath::API | |
use Goliath::Rack::SimpleAroundwareFactory, ApiValidationAroundware | |
use Goliath::Rack::Heartbeat | |
get "/version", Version | |
not_found('/') do | |
run Proc.new { |env| [404, {"Content-Type" => "text/html"}, [" | |
<html> | |
<head><title>Test</title></head> | |
<body> | |
<p>WOrd up</p> | |
</body> | |
</html> | |
"]] } | |
end | |
end |
Actually:
require 'goliath'
class ApiValidationAroundware
include Goliath::Rack::SimpleAroundware
end
class Test < Goliath::API
use Goliath::Rack::SimpleAroundwareFactory, ApiValidationAroundware
use Goliath::Rack::Heartbeat
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simplified the test case to the below. Query for /status hangs.