Skip to content

Instantly share code, notes, and snippets.

@danhealy
Created December 31, 2011 23:26
Show Gist options
  • Save danhealy/1545633 to your computer and use it in GitHub Desktop.
Save danhealy/1545633 to your computer and use it in GitHub Desktop.
Error with Goliath & BarrierAroundware
This gist is an example of an error I'm seeing on a much larger Goliath app. There are two issues:
1: The 'body' variable in the aroundware seems to be receiving the desired body converted to an array.
2: The presence of the aroundware generates a 2nd 500 response due to "received response for a non-pending request!"
Thanks.
* Note: The response is the entire response received. It gets cut off.
require 'rubygems'
require "bundler"
Bundler.setup
Bundler.require(:default)
require 'json'
class MyCustomAroundware
include Goliath::Rack::BarrierAroundware
def pre_process
return Goliath::Connection::AsyncResponse
end
def post_process
puts status
puts headers
puts body
[status, headers.merge("Content-Type" => "application/json"), body.to_json]
end
end
class HelloWorldEndpoint < Goliath::API
def response(env)
[200, {}, {:message => "Hello World"}]
end
end
class AroundwareTest < Goliath::API
use Goliath::Rack::BarrierAroundwareFactory, MyCustomAroundware
map "/hello", HelloWorldEndpoint
end
source :rubygems
gem "eventmachine", ">= 1.0.0.beta.3"
gem 'goliath', :git => 'git://github.com/postrank-labs/goliath.git'
gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git'
$ bundle exec ruby aroundware_test.rb -sv
[90334:INFO] 2012-01-01 11:34:19 :: Starting server on 0.0.0.0:9000 in development mode. Watch out for stones.
200
{"Content-Length"=>"25"}
[:message, "Hello World"]
[90334:INFO] 2012-01-01 11:34:25 :: Status: 200, Content-Length: 25, Response Time: 63.13ms
[90334:ERROR] 2012-01-01 11:34:25 :: received response for a non-pending request!
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/bundler/gems/goliath-d4e97f067f3d/lib/goliath/rack/barrier_aroundware.rb:156:in `accept_response'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/bundler/gems/goliath-d4e97f067f3d/lib/goliath/rack/simple_aroundware_factory.rb:82:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/bundler/gems/goliath-d4e97f067f3d/lib/goliath/rack/async_middleware.rb:73:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/gems/rack-1.4.0/lib/rack/content_length.rb:14:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:114:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:91:in `block in new'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/gems/rack-1.4.0/lib/rack/reloader.rb:44:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/gems/rack-1.4.0/lib/rack/reloader.rb:44:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p290@goliath-orig/bundler/gems/goliath-d4e97f067f3d/lib/goliath/request.rb:139:in `block in process'
[90334:INFO] 2012-01-01 11:34:25 :: Status: 500, Content-Length: 25, Response Time: 63.61ms
HTTP/1.1 200 OK
Content-Length: 25
Content-Type: application/json
Server: Goliath
Date: Sun, 01 Jan 2012 19:34:25 GMT
["[:message, \"Hello Worl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment