Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created January 15, 2012 18:27
Show Gist options
  • Save ruprict/1616686 to your computer and use it in GitHub Desktop.
Save ruprict/1616686 to your computer and use it in GitHub Desktop.
SimpleAroundAware issue
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
@dj2
Copy link

dj2 commented Jan 20, 2012

Simplified the test case to the below. Query for /status hangs.

require 'goliath'

class ApiValidationAroundware
  include Goliath::Rack::SimpleAroundware

  def pre_process
    Goliath::Connection::AsyncResponse
  end

  def post_process
    [status, headers, body]
  end
end

class Test < Goliath::API
  use Goliath::Rack::SimpleAroundwareFactory, ApiValidationAroundware
  use Goliath::Rack::Heartbeat
end

@dj2
Copy link

dj2 commented Jan 20, 2012

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