reel-rack 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06803d93eb880a4e42e5fb03eea26d6fc76ab3ac
4
+ data.tar.gz: 0fc1f1eb4017f42f90e941c2a0ce3c2f16e75a09
5
+ SHA512:
6
+ metadata.gz: 4eab959959f60719c65dbf3d01f87c1eea135800b4fd6593853a5d13eadf1caa065a5fe66017acce699726aeab6b3c4fd90aee4fb5e670f63e717e7e349af950
7
+ data.tar.gz: babb61ae76ce703637f9de0ba9474114db7aae3ff5ad0b5ffc1f20c35a14736afa892eceec271cbd167fa896c6935938d21154f0ef6c95284d55d90cfb9be2ff
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --default_path spec
@@ -0,0 +1,15 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - ruby-head
5
+ - jruby-19mode
6
+ - jruby-head
7
+ - rbx-19mode
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ - rvm: jruby-head
13
+
14
+ notifications:
15
+ irc: "irc.freenode.org#celluloid"
@@ -0,0 +1,3 @@
1
+ 0.0.0
2
+ -----
3
+ * Initial proof-of-concept
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'celluloid', github: 'celluloid/celluloid', branch: 'master'
4
+ gem 'celluloid-io', github: 'celluloid/celluloid-io', branch: 'master'
5
+
6
+ gem 'reel', github: 'celluloid/reel'
7
+ gem 'http', github: 'tarcieri/http'
8
+
9
+ gem 'coveralls', require: false
10
+
11
+ # Specify your gem's dependencies in reel-app.gemspec
12
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tony Arcieri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ Reel::Rack
2
+ ==========
3
+
4
+ [![Build Status](https://secure.travis-ci.org/celluloid/reel-rack.png?branch=master)](http://travis-ci.org/celluloid/reel-rack)
5
+ [![Code Climate](https://codeclimate.com/github/celluloid/reel-rack.png)](https://codeclimate.com/github/celluloid/reel-rack)
6
+ [![Coverage Status](https://coveralls.io/repos/celluloid/reel-rack/badge.png?branch=master)](https://coveralls.io/r/celluloid/reel-rack)
7
+
8
+ A Rack adapter for [Reel][reel], the [Celluloid::IO][celluloidio] web server.
9
+
10
+ [reel]: https://github.com/celluloid/reel
11
+ [celluloidio]: https://github.com/celluloid/celluloid-io
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'reel-rack'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install reel-rack
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ Dir[File.expand_path("../tasks/**/*.rake", __FILE__)].each { |task| load task }
3
+
4
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'reel/rack/cli'
4
+
5
+ Reel::Rack::CLI.new(ARGV).run
@@ -0,0 +1,41 @@
1
+ require 'reel/rack/server'
2
+
3
+ module Rack
4
+ module Handler
5
+ class Reel
6
+ DEFAULT_OPTIONS = {
7
+ :host => "0.0.0.0",
8
+ :port => 3000,
9
+ :quiet => false
10
+ }
11
+
12
+ def self.run(app, options = {})
13
+ options = DEFAULT_OPTIONS.merge(options)
14
+
15
+ unless options[:quiet]
16
+ app = Rack::CommonLogger.new(app, STDOUT)
17
+ end
18
+
19
+ if options[:environment]
20
+ ENV['RACK_ENV'] = options[:environment].to_s
21
+ end
22
+
23
+ Celluloid.logger.info "A Reel good HTTP server! (Codename \"#{::Reel::CODENAME}\")"
24
+ Celluloid.logger.info "Listening on #{options[:host]}:#{options[:port]}"
25
+
26
+ supervisor = ::Reel::Rack::Server.supervise_as(:reel_rack_server, app, options)
27
+
28
+ begin
29
+ sleep
30
+ rescue Interrupt
31
+ Celluloid.logger.info "Interrupt received... shutting down"
32
+ supervisor.terminate
33
+ Celluloid.join(supervisor)
34
+ Celluloid.logger.info "That's all, folks!"
35
+ end
36
+ end
37
+ end
38
+
39
+ register :reel, Reel
40
+ end
41
+ end
@@ -0,0 +1,2 @@
1
+ require 'reel/rack/version'
2
+ require 'rack/handler/reel'
@@ -0,0 +1,17 @@
1
+ require 'reel/rack'
2
+
3
+ module Reel
4
+ module Rack
5
+ class CLI
6
+ def initialize(argv)
7
+ @argv = argv
8
+ @rackup = "config.ru"
9
+ end
10
+
11
+ def run
12
+ app, options = ::Rack::Builder.parse_file(@rackup)
13
+ ::Rack::Handler::Reel.run(app, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,62 @@
1
+
2
+ # Adapted from code orinially Copyright (c) 2013 Jonathan Stott
3
+
4
+ require 'reel'
5
+ require 'rack'
6
+
7
+ module Reel
8
+ module Rack
9
+ class Server < Server
10
+ attr_reader :app
11
+ def initialize(app, options)
12
+ raise ArgumentError, "no host given" unless options[:host]
13
+ raise ArgumentError, "no port given" unless options[:port]
14
+
15
+ super(options[:host], options[:port], &method(:on_connection))
16
+ @app = app
17
+ end
18
+
19
+ def on_connection(connection)
20
+ connection.each_request do |request|
21
+ if request.websocket?
22
+ request.respond :bad_request, "WebSockets not supported"
23
+ else
24
+ route_request request
25
+ end
26
+ end
27
+ end
28
+
29
+ def route_request(request)
30
+ options = {
31
+ :method => request.method,
32
+ :input => request.body.to_s,
33
+ "REMOTE_ADDR" => request.remote_addr
34
+ }.merge(convert_headers(request.headers))
35
+
36
+ status, headers, body = app.call ::Rack::MockRequest.env_for(request.url, options)
37
+
38
+ if body.respond_to? :each
39
+ request.respond status_symbol(status), headers.merge(:transfer_encoding => :chunked)
40
+ body.each { |chunk| request << chunk }
41
+ request.finish_response
42
+ else
43
+ request.respond status_symbol(status), headers, body
44
+ end
45
+
46
+ body.close if body.respond_to? :close
47
+ end
48
+
49
+ def convert_headers(headers)
50
+ Hash[headers.map { |key, value| ['HTTP_' + key.upcase.gsub('-','_'),value ] }]
51
+ end
52
+
53
+ def status_symbol(status)
54
+ if status.is_a?(Fixnum)
55
+ Http::Response::STATUS_CODES[status].downcase.gsub(/\s|-/, '_').to_sym
56
+ else
57
+ status.to_sym
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ module Reel
2
+ module Rack
3
+ VERSION = "0.0.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reel/rack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reel-rack"
8
+ spec.version = Reel::Rack::VERSION
9
+ spec.authors = ["Tony Arcieri", "Jonathan Stott"]
10
+ spec.email = ["tony.arcieri@gmail.com"]
11
+ spec.description = "Rack adapter for Reel"
12
+ spec.summary = "Rack adapter for Reel, a Celluloid::IO web server"
13
+ spec.homepage = "https://github.com/celluloid/reel-rack"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "reel", ">= 0.4.0.pre2"
22
+ spec.add_runtime_dependency "rack", "1.5.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,23 @@
1
+
2
+ require 'spec_helper'
3
+ require 'net/http'
4
+
5
+ describe Reel::Rack::Server do
6
+ let(:host) { "127.0.0.1" }
7
+ let(:port) { 30000 }
8
+ let(:body) { "hello world" }
9
+
10
+ subject do
11
+ app = proc { [200, {"Content-Type" => "text/plain"}, body] }
12
+ described_class.new(app, :host => host, :port => port)
13
+ end
14
+
15
+ it "runs a basic Hello World app" do
16
+ # Hax to wait for server to be started
17
+ subject.inspect
18
+
19
+ expect(Net::HTTP.get(URI("http://#{host}:#{port}"))).to eq body
20
+
21
+ subject.terminate
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'bundler/setup'
5
+ require 'reel/rack'
6
+
7
+ class ExampleRequest
8
+ extend Forwardable
9
+ def_delegators :@headers, :[], :[]=
10
+ attr_accessor :method, :path, :version, :body
11
+
12
+ def initialize(method = :get, path = "/", version = "1.1", headers = {}, body = nil)
13
+ @method = method.to_s.upcase
14
+ @path = path
15
+ @version = "1.1"
16
+ @headers = {
17
+ 'Host' => 'www.example.com',
18
+ 'Connection' => 'keep-alive',
19
+ 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.78 S',
20
+ 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
21
+ 'Accept-Encoding' => 'gzip,deflate,sdch',
22
+ 'Accept-Language' => 'en-US,en;q=0.8',
23
+ 'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
24
+ }.merge(headers)
25
+
26
+ @body = nil
27
+ end
28
+
29
+ def to_s
30
+ if @body && !@headers['Content-Length']
31
+ @headers['Content-Length'] = @body.length
32
+ end
33
+
34
+ "#{@method} #{@path} HTTP/#{@version}\r\n" <<
35
+ @headers.map { |k, v| "#{k}: #{v}" }.join("\r\n") << "\r\n\r\n" <<
36
+ (@body ? @body : '')
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reel-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tony Arcieri
8
+ - Jonathan Stott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: reel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.4.0.pre2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 0.4.0.pre2
28
+ - !ruby/object:Gem::Dependency
29
+ name: rack
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.5.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.5.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Rack adapter for Reel
85
+ email:
86
+ - tony.arcieri@gmail.com
87
+ executables:
88
+ - reel-rack
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .travis.yml
95
+ - CHANGES.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/reel-rack
101
+ - lib/rack/handler/reel.rb
102
+ - lib/reel/rack.rb
103
+ - lib/reel/rack/cli.rb
104
+ - lib/reel/rack/server.rb
105
+ - lib/reel/rack/version.rb
106
+ - log/.gitignore
107
+ - reel-rack.gemspec
108
+ - spec/reel/rack/server_spec.rb
109
+ - spec/spec_helper.rb
110
+ - tasks/rspec.rake
111
+ homepage: https://github.com/celluloid/reel-rack
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Rack adapter for Reel, a Celluloid::IO web server
135
+ test_files:
136
+ - spec/reel/rack/server_spec.rb
137
+ - spec/spec_helper.rb