Skip to content

Instantly share code, notes, and snippets.

@bbozo
Last active December 20, 2015 15:49
Show Gist options
  • Save bbozo/6157377 to your computer and use it in GitHub Desktop.
Save bbozo/6157377 to your computer and use it in GitHub Desktop.
HTTP server service for Torquebox, http_parser.rb gem problem
bbozo@uhurajr-ubuntu:~/dev/test_mri_app$ curl localhost:8081
curl: (56) Recv failure: Connection reset by peer
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.14)
actionpack (= 3.2.14)
mail (~> 2.5.4)
actionpack (3.2.14)
activemodel (= 3.2.14)
activesupport (= 3.2.14)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.14)
activesupport (= 3.2.14)
builder (~> 3.0.0)
activerecord (3.2.14)
activemodel (= 3.2.14)
activesupport (= 3.2.14)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activerecord-jdbc-adapter (1.2.9.1)
activerecord-jdbcsqlite3-adapter (1.2.9)
activerecord-jdbc-adapter (~> 1.2.9)
jdbc-sqlite3 (~> 3.7.2)
activeresource (3.2.14)
activemodel (= 3.2.14)
activesupport (= 3.2.14)
activesupport (3.2.14)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arel (3.0.2)
bouncy-castle-java (1.5.0147)
builder (3.0.4)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.3)
erubis (2.7.0)
eventmachine (1.0.3-java)
execjs (1.4.0)
multi_json (~> 1.0)
hike (1.2.3)
http_parser (0.1.3)
i18n (0.6.4)
jdbc-sqlite3 (3.7.2.1)
journey (1.0.4)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jruby-openssl (0.8.8)
bouncy-castle-java (>= 1.5.0147)
json (1.8.0)
json (1.8.0-java)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.23)
multi_json (1.7.8)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.14)
actionmailer (= 3.2.14)
actionpack (= 3.2.14)
activerecord (= 3.2.14)
activeresource (= 3.2.14)
activesupport (= 3.2.14)
bundler (~> 1.0)
railties (= 3.2.14)
railties (3.2.14)
actionpack (= 3.2.14)
activesupport (= 3.2.14)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.1.0)
rdoc (3.12.2)
json (~> 1.4)
sass (3.2.10)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
therubyrhino (2.0.2)
therubyrhino_jar (>= 1.7.3)
therubyrhino_jar (1.7.4)
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
uglifier (2.1.2)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
PLATFORMS
java
DEPENDENCIES
activerecord-jdbcsqlite3-adapter
coffee-rails (~> 3.2.1)
eventmachine
http_parser
jquery-rails
jruby-openssl
rails (= 3.2.14)
sass-rails (~> 3.2.3)
therubyrhino
uglifier (>= 1.0.3)
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.14)
actionpack (= 3.2.14)
mail (~> 2.5.4)
actionpack (3.2.14)
activemodel (= 3.2.14)
activesupport (= 3.2.14)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.14)
activesupport (= 3.2.14)
builder (~> 3.0.0)
activerecord (3.2.14)
activemodel (= 3.2.14)
activesupport (= 3.2.14)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.14)
activemodel (= 3.2.14)
activesupport (= 3.2.14)
activesupport (3.2.14)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.3)
erubis (2.7.0)
eventmachine (1.0.3)
execjs (1.4.0)
multi_json (~> 1.0)
hike (1.2.3)
http_parser (0.1.3)
i18n (0.6.4)
journey (1.0.4)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.0)
libv8 (3.11.8.17)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.23)
multi_json (1.7.8)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.14)
actionmailer (= 3.2.14)
actionpack (= 3.2.14)
activerecord (= 3.2.14)
activeresource (= 3.2.14)
activesupport (= 3.2.14)
bundler (~> 1.0)
railties (= 3.2.14)
railties (3.2.14)
actionpack (= 3.2.14)
activesupport (= 3.2.14)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.1.0)
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.5)
sass (3.2.10)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.7)
therubyracer (0.11.4)
libv8 (~> 3.11.8.12)
ref
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
uglifier (2.1.2)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
PLATFORMS
ruby
DEPENDENCIES
coffee-rails (~> 3.2.1)
eventmachine
http_parser
jquery-rails
rails (= 3.2.14)
sass-rails (~> 3.2.3)
sqlite3
therubyracer
uglifier (>= 1.0.3)
class HttpServerService
def initialize options = {}
end
def start
Thread.abort_on_exception = true
@thread = Thread.new do
EM.run do
EM.start_server "0.0.0.0", 8081, HttpServerWithPersistance
puts "running"
end
end
end
def stop
EM.try :stop
@thread.join
end
module HttpServerWithPersistance
attr_accessor :parser
attr_accessor :counter
def post_init
puts "-- NEW CONNECTION"
self.parser = Http::Parser.new(self)
self.counter = 0
end
def receive_data(data)
parser << data
end
def on_message_begin
@headers = nil
@body = ''
end
def on_headers_complete(headers)
@headers = headers
end
def on_body(chunk)
@body << chunk
end
def on_message_complete
p [@headers, @body]
self.counter += 1
send_http_response content: "OK, response no #{counter}"
self.parser = Http::Parser.new(self) # await new request
end
def unbind
puts "-- someone disconnected from the echo server!"
end
private
def send_http_response options = {}
response = EM::DelegatedHttpResponse.new(self)
response.status = 200
response.content_type 'text/html'
response.content = ''
response.keep_connection_open keep_connection_open?
options.each do |k,v|
response.send "#{k}=", v
end
response.send_response
end
def keep_connection_open?
@headers['Connection'].to_s.downcase == 'keep-alive'
end
end
end
bbozo@uhurajr-ubuntu:~/dev/test_jruby_app$ rails c
Loading development environment (Rails 3.2.14)
jruby-1.7.4 :001 > x = HttpServerService.new; x.start
=> #<Thread:0x7fc89b2b run>
jruby-1.7.4 :002 > running
jruby-1.7.4 :003 > -- NEW CONNECTION
TypeError: can't convert HttpServerService::HttpServerWithPersistance::EM_CONNECTION_CLASS into Hash
merge at org/jruby/RubyHash.java:1756
initialize at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/http_parser-0.1.3/lib/http/native_parser.rb:83
post_init at /media/sf_Shared/dev/test_jruby_app/app/models/http_server_service.rb:29
new at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/eventmachine-1.0.3-java/lib/em/connection.rb:58
instance_eval at org/jruby/RubyBasicObject.java:1735
new at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/eventmachine-1.0.3-java/lib/em/connection.rb:49
event_callback at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/eventmachine-1.0.3-java/lib/eventmachine.rb:1467
eventCallback at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/eventmachine-1.0.3-java/lib/jeventmachine.rb:92
run_machine at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/eventmachine-1.0.3-java/lib/jeventmachine.rb:111
run at /home/bbozo/.rvm/gems/jruby-1.7.4/gems/eventmachine-1.0.3-java/lib/eventmachine.rb:187
start at /media/sf_Shared/dev/test_jruby_app/app/models/http_server_service.rb:11
bbozo@uhurajr-ubuntu:~/dev/test_mri_app$ rails c
Loading development environment (Rails 3.2.14)
1.9.3-p286 :001 > x = HttpServerService.new; x.start
=> #<Thread:0x00000003a69b60 run>
running1.9.3-p286 :002 >
1.9.3-p286 :003 > -- NEW CONNECTION
/home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/http_parser-0.1.3/lib/http/native_parser.rb:83:in `merge': can't convert HttpServerService::HttpServerWithPersistance::EM_CONNECTION_CLASS into Hash (TypeError)
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/http_parser-0.1.3/lib/http/native_parser.rb:83:in `initialize'
from /media/sf_Shared/dev/test_mri_app/app/models/http_server_service.rb:29:in `new'
from /media/sf_Shared/dev/test_mri_app/app/models/http_server_service.rb:29:in `post_init'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.3/lib/em/connection.rb:58:in `block in new'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.3/lib/em/connection.rb:49:in `instance_eval'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.3/lib/em/connection.rb:49:in `new'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.3/lib/eventmachine.rb:1467:in `event_callback'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
from /home/bbozo/.rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
from /media/sf_Shared/dev/test_mri_app/app/models/http_server_service.rb:11:in `block in start'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment