Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Reel #51

Merged
merged 17 commits into from

8 participants

@seancribbs
Owner

Adds Reel as a server adapter.

seancribbs and others added some commits
@seancribbs seancribbs WIP Reel adapter. [ci skip] a2ae664
@SebastianEdwards SebastianEdwards Fixing Reel adapter.
- Ensure callback only runs when connection has a request.
- Pull 'Host' header out with fetch to bypass transform_key.
- Reference correct variable in body-prepping case statement.
d404376
@SebastianEdwards SebastianEdwards Use streaming response to handle enumerable bodies. f5a08cd
@seancribbs seancribbs Merge pull request #46 from SebastianEdwards/reel
Fix Reel Adapter
e0b21df
@tarcieri tarcieri Reel::Response supports Enumerables natively now cbf7490
@seancribbs seancribbs Merge pull request #50 from tarcieri/reel
Update to current Reel API
da86612
@bernd
Collaborator

I like it. +1

@tarcieri
Collaborator

What does this need to get merged? Just merge master?

@tarcieri
Collaborator

Tests would probably be helpful, and the "if wreq" should probably be "while wreq" (for Keep-Alive support):

https://github.com/seancribbs/webmachine-ruby/blob/cbf74908b658c280024a63e16ed864aa7c64d494/lib/webmachine/adapters/reel.rb#L23

@samwgoldman
Collaborator

Seems like the extracted LazyRequestBody class should be useful for the Rack and Mongrel adapters as well. There are slight differences between the adapters' RequestBody implementations as is. Once this is merged we should look into consolidating them.

@seancribbs
Owner
  1. Tests, yes. I was just starting a PR so we can keep track that this is here.
  2. We should also probably autoload the Reel adapter to avoid blindly requiring it.
  3. We should make the gem dep sane.
@tarcieri
Collaborator

I just released Reel 0.1.0 and fixed the gem dependencies

nicholaswyoung and others added some commits
@nicholaswyoung nicholaswyoung One small tweak...
Good to go now. Reel adapter spec fixed.
be7cf45
@tarcieri tarcieri Merge branch 'originalmachine-reel' into reel
Conflicts:
	webmachine.gemspec
5f26d09
@tarcieri tarcieri Merge branch 'master' into reel
Conflicts:
	lib/webmachine/adapters.rb
	webmachine.gemspec
5c09bb8
@tarcieri
Collaborator

@seancribbs I think this is ready to merge...

@travisbot

This pull request fails (merged 5c09bb8 into aedcfa2).

@tarcieri
Collaborator

Belay that ;) Investigating...

@tarcieri
Collaborator

Hmmm, looks like we need to disable the Reel specs on 1.8...

@travisbot

This pull request fails (merged 5fdedc0 into aedcfa2).

@tarcieri
Collaborator

@seancribbs okay, this should be ready to merge aside from that unrelated test failure on JRuby 1.9. It's working fine for me here

@travisbot

This pull request fails (merged 2eb6323 into aedcfa2).

@lgierth

The .gemspec is only being evaluated when building the gem and when developing using Bundler, so this will result in different gems being built depending on the Ruby version you run gem build on.

Collaborator

It's a development dependency. Is that really an issue?

Do you have a better suggestion?

Collaborator

An alternative might be to pull development dependencies in through the Gemfile instead of the gemspec

@seancribbs
Owner

@tarcieri If you can fix that one thing in the gemspec (the 1.9 conditional stuff), this should be ready to merge.

@travisbot

This pull request fails (merged 7baa24d into aedcfa2).

@travisbot

This pull request passes (merged f8e95ac into aedcfa2).

@tarcieri
Collaborator

@seancribbs should be good to go now

@seancribbs
Owner

@tarcieri What's wrong with JRuby 1.9-mode?

@tarcieri
Collaborator

@seancribbs it appears to be related to mongrel. See: http://travis-ci.org/#!/seancribbs/webmachine-ruby/jobs/2171020

I enabled checks on Travis for 1.9 mode for both JRuby and rbx to check Reel because it's 1.9 only, however it appears that mongrel doesn't work on JRuby in 1.9 mode.

@seancribbs
Owner

Ok, we might be able to work around that. I'll look into it after I finish this feature branch.

@travisbot

This pull request fails (merged 3f8028b into aedcfa2).

@tarcieri
Collaborator

Well that build failure seems rather odd... I'll investigate.

@tarcieri
Collaborator

I believe you can use :platform => :cruby to accomplish the same effect

@seancribbs
Owner

@tarcieri Yeah, according to the Gemfile manual, 'ruby_19' should be sufficient to exclude JRuby. What gives?

@seancribbs
Owner

@tarcieri Does Reel work on JRuby in 1.9 mode?

@tarcieri
Collaborator

@seancribbs there's no reason I know of why it shouldn't. It doesn't look like reel is getting bundled per your comment about 'ruby_19'

@travisbot

This pull request fails (merged a6a02e1 into aedcfa2).

@travisbot

This pull request passes (merged 82bd60e into aedcfa2).

@seancribbs seancribbs merged commit aaefa6d into master

1 check passed

Details default The Travis build passed
@nicholaswyoung

Awesome to see this get merged. Thanks, @seancribbs and @tarcieri .

@tarcieri
Collaborator

w00t! Glad this finally landed, although I already see #67... will take a look

@bernd bernd referenced this pull request
Merged

Unbreak CI for JRuby 1.8 #75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @seancribbs

    WIP Reel adapter. [ci skip]

    seancribbs authored
Commits on May 14, 2012
  1. @SebastianEdwards

    Fixing Reel adapter.

    SebastianEdwards authored
    - Ensure callback only runs when connection has a request.
    - Pull 'Host' header out with fetch to bypass transform_key.
    - Reference correct variable in body-prepping case statement.
Commits on May 16, 2012
  1. @SebastianEdwards
Commits on May 17, 2012
  1. @seancribbs

    Merge pull request #46 from SebastianEdwards/reel

    seancribbs authored
    Fix Reel Adapter
Commits on Jun 3, 2012
  1. @tarcieri
  2. @seancribbs

    Merge pull request #50 from tarcieri/reel

    seancribbs authored
    Update to current Reel API
Commits on Jul 13, 2012
  1. @tarcieri

    Use reel gem

    tarcieri authored
Commits on Aug 18, 2012
  1. @nicholaswyoung

    One small tweak...

    nicholaswyoung authored
    Good to go now. Reel adapter spec fixed.
  2. @tarcieri

    Merge branch 'originalmachine-reel' into reel

    tarcieri authored
    Conflicts:
    	webmachine.gemspec
  3. @tarcieri

    Merge branch 'master' into reel

    tarcieri authored
    Conflicts:
    	lib/webmachine/adapters.rb
    	webmachine.gemspec
  4. @tarcieri
  5. @tarcieri

    HTTP KA support

    tarcieri authored
Commits on Aug 19, 2012
  1. @tarcieri
  2. @tarcieri
Commits on Aug 20, 2012
  1. @seancribbs
  2. @seancribbs
  3. @seancribbs

    Use == instead of be.

    seancribbs authored
This page is out of date. Refresh to see the latest.
View
6 .travis.yml
@@ -2,6 +2,8 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- - rbx
- - jruby
+ - jruby-18mode
+ - jruby-19mode
+ - rbx-18mode
+ - rbx-19mode
bundler_args: --without=guard,docs
View
6 Gemfile
@@ -6,6 +6,12 @@ gemspec
gem 'bundler'
+group :webservers do
+ gem 'mongrel', '~> 1.2.beta', :platform => [:mri, :rbx]
+ gem 'reel', '>= 0.1.0', :platform => [:ruby_19, :jruby]
+ gem 'hatetepe', '~> 0.5'
+end
+
group :guard do
gem 'guard-rspec'
case RbConfig::CONFIG['host_os']
View
2  lib/webmachine/adapters.rb
@@ -1,3 +1,4 @@
+require 'webmachine/adapters/lazy_request_body'
require 'webmachine/adapters/webrick'
module Webmachine
@@ -5,6 +6,7 @@ module Webmachine
# application servers.
module Adapters
autoload :Mongrel, 'webmachine/adapters/mongrel'
+ autoload :Reel, 'webmachine/adapters/reel'
autoload :Hatetepe, 'webmachine/adapters/hatetepe'
end
end
View
32 lib/webmachine/adapters/lazy_request_body.rb
@@ -0,0 +1,32 @@
+
+module Webmachine
+ module Adapters
+ # Wraps a request body so that it can be passed to
+ # {Request} while still lazily evaluating the body.
+ class LazyRequestBody
+ def initialize(request)
+ @request = request
+ end
+
+ # Converts the body to a String so you can work with the entire
+ # thing.
+ def to_s
+ @value ? @value.join : @request.body
+ end
+
+ # Iterates over the body in chunks. If the body has previously
+ # been read, this method can be called again and get the same
+ # sequence of chunks.
+ # @yield [chunk]
+ # @yieldparam [String] chunk a chunk of the request body
+ def each
+ if @value
+ @value.each {|chunk| yield chunk }
+ else
+ @value = []
+ @request.body {|chunk| @value << chunk; yield chunk }
+ end
+ end
+ end # class RequestBody
+ end # module Adapters
+end # module Webmachine
View
41 lib/webmachine/adapters/reel.rb
@@ -0,0 +1,41 @@
+require 'reel'
+require 'webmachine/version'
+require 'webmachine/headers'
+require 'webmachine/request'
+require 'webmachine/response'
+require 'webmachine/dispatcher'
+require 'webmachine/chunked_body'
+
+module Webmachine
+ module Adapters
+ class Reel < Adapter
+ def run
+ options = {
+ :port => configuration.port,
+ :host => configuration.ip
+ }.merge(configuration.adapter_options)
+ server = ::Reel::Server.supervise(options[:host], options[:port], &method(:process))
+ trap("INT"){ server.terminate; exit 0 }
+ sleep
+ end
+
+ def process(connection)
+ while wreq = connection.request
+ header = Webmachine::Headers[wreq.headers.dup]
+ requri = URI::HTTP.build(:host => header.fetch('Host').split(':').first,
+ :port => header.fetch('Host').split(':').last.to_i,
+ :path => wreq.url.split('?').first,
+ :query => wreq.url.split('?').last)
+ request = Webmachine::Request.new(wreq.method.to_s.upcase,
+ requri,
+ header,
+ LazyRequestBody.new(wreq))
+ response = Webmachine::Response.new
+ @dispatcher.dispatch(request,response)
+
+ connection.respond ::Reel::Response.new(response.code, response.headers, response.body)
+ end
+ end
+ end
+ end
+end
View
31 lib/webmachine/adapters/webrick.rb
@@ -35,7 +35,7 @@ def service(wreq, wres)
request = Webmachine::Request.new(wreq.request_method,
wreq.request_uri,
header,
- RequestBody.new(wreq))
+ LazyRequestBody.new(wreq))
response = Webmachine::Response.new
@dispatcher.dispatch(request, response)
wres.status = response.code.to_i
@@ -61,35 +61,6 @@ def service(wreq, wres)
end
end
end # class Server
-
- # Wraps the WEBrick request body so that it can be passed to
- # {Request} while still lazily evaluating the body.
- class RequestBody
- def initialize(request)
- @request = request
- end
-
- # Converts the body to a String so you can work with the entire
- # thing.
- def to_s
- @value ? @value.join : @request.body
- end
-
- # Iterates over the body in chunks. If the body has previously
- # been read, this method can be called again and get the same
- # sequence of chunks.
- # @yield [chunk]
- # @yieldparam [String] chunk a chunk of the request body
- def each
- if @value
- @value.each {|chunk| yield chunk }
- else
- @value = []
- @request.body {|chunk| @value << chunk; yield chunk }
- end
- end
- end # class RequestBody
-
end # module WEBrick
end # module Adapters
end # module Webmachine
View
23 spec/webmachine/adapters/reel_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+if RUBY_VERSION >= "1.9"
+ describe Webmachine::Adapters::Reel do
+ let(:configuration) { Webmachine::Configuration.default }
+ let(:dispatcher) { Webmachine::Dispatcher.new }
+ let(:adapter) do
+ described_class.new(configuration, dispatcher)
+ end
+
+ it 'inherits from Webmachine::Adapter' do
+ adapter.should be_a_kind_of(Webmachine::Adapter)
+ end
+
+ it 'implements #run' do
+ adapter.should respond_to(:run)
+ end
+
+ it 'implements #process' do
+ adapter.should respond_to(:process)
+ end
+ end
+end
View
2  spec/webmachine/errors_spec.rb
@@ -7,7 +7,7 @@
res = Webmachine::Response.new
Webmachine.render_error(404, req, res)
- res.code.should be(404)
+ res.code.should == 404
end
end
end
View
2  webmachine.gemspec
@@ -19,8 +19,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
gem.add_development_dependency(%q<yard>, ["~> 0.7.3"])
gem.add_development_dependency(%q<rake>)
- gem.add_development_dependency(%q<mongrel>, ['~>1.2.beta'])
- gem.add_development_dependency(%q<hatetepe>, ['~> 0.5'])
gem.add_development_dependency(%q<rack>)
gem.add_development_dependency(%q<rack-test>)
Something went wrong with that request. Please try again.