falcon 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffde5c3cd28c595389deccb1c4252be6d08b1de3
4
- data.tar.gz: 34a3af82b5e312e0c942142aab09401f1ad3335e
3
+ metadata.gz: c34a59f385757f96b63f7a7072fb377e72832a9c
4
+ data.tar.gz: 614317654daa502e8521be52ffa7730b16068c29
5
5
  SHA512:
6
- metadata.gz: 41f5be797dffbb54206cef86258b25efee38913270099c32b72dcdb02fea16f5add4b1a2c9b6e5291aef33171351863e1dd1f01f9801858079b117abe0d869f6
7
- data.tar.gz: 1dfe0c9e4097c51029592fbd5b351c3ccb98d1d557205587bafb18834e737ea308c8e88162aebc484cf6927e339fd62fcd50ab155eef9402c03acf2176a4b68d
6
+ metadata.gz: 0fd5700a68dcba473e0f4c3e9e16dc77953609462749c2dbe14d8eed732e34911fc48821bde26508c868656415bfd08a2a08080e0866ef8ce5b55abf2e91097b
7
+ data.tar.gz: b283f4fb9e3cd6d6e49a923e6a24470851e2f04ac3e4433d310884f9aa6b5302ae66d261a2196d37fcc79758b8f49f66a5e14db26c2b3867f3c643b0000ddf0a
@@ -2,16 +2,18 @@ language: ruby
2
2
  sudo: false
3
3
  dist: trusty
4
4
  cache: bundler
5
- rvm:
6
- - 2.0
7
- - 2.1
8
- - 2.2
9
- - 2.3
10
- - 2.4
11
- - jruby-head
12
- - ruby-head
13
- - rbx-3
5
+
14
6
  matrix:
7
+ include:
8
+ - rvm: 2.0
9
+ - rvm: 2.1
10
+ - rvm: 2.2
11
+ - rvm: 2.3
12
+ - rvm: 2.4
13
+ - rvm: jruby-head
14
+ env: JRUBY_OPTS="--debug -X+O"
15
+ - rvm: ruby-head
16
+ - rvm: rbx-3
15
17
  allow_failures:
16
18
  - rvm: ruby-head
17
19
  - rvm: jruby-head
@@ -0,0 +1,5 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem "sinatra"
5
+ gem "falcon"
@@ -0,0 +1,50 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ async (1.2.2)
5
+ nio4r
6
+ timers (~> 4.1)
7
+ async-container (0.2.2)
8
+ async (~> 1.0)
9
+ async-http (0.6.0)
10
+ async (~> 1.1)
11
+ async-io (~> 1.0)
12
+ async-io (1.2.1)
13
+ async (~> 1.0)
14
+ falcon (0.6.0)
15
+ async-container (~> 0.1)
16
+ async-http (~> 0.3)
17
+ async-io (~> 1.1)
18
+ rack (>= 1.0)
19
+ samovar (~> 1.3)
20
+ hitimes (1.2.6)
21
+ mapping (1.1.1)
22
+ mustermann (1.0.1)
23
+ nio4r (2.2.0)
24
+ rack (2.0.4)
25
+ rack-protection (2.0.0)
26
+ rack
27
+ rainbow (2.2.2)
28
+ rake
29
+ rake (12.3.0)
30
+ samovar (1.8.0)
31
+ mapping (~> 1.0)
32
+ rainbow (~> 2.0)
33
+ sinatra (2.0.0)
34
+ mustermann (~> 1.0)
35
+ rack (~> 2.0)
36
+ rack-protection (= 2.0.0)
37
+ tilt (~> 2.0)
38
+ tilt (2.0.8)
39
+ timers (4.1.2)
40
+ hitimes
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ falcon
47
+ sinatra
48
+
49
+ BUNDLED WITH
50
+ 1.16.0
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env falcon --verbose serve -c
2
+
3
+ # Save this as `config.ru`, make it executable and then run it (or run falcon serve by hand)
4
+
5
+ # Middleware that responds to incoming requests:
6
+ require 'sinatra/base'
7
+ class MyApp < Sinatra::Base
8
+ get "/" do
9
+ "hello world"
10
+ end
11
+ end
12
+
13
+ # Build the middleware stack:
14
+ use MyApp # Then, it will get to Sinatra.
15
+ run lambda {|env| [404, {}, []]} # Bottom of the stack, give 404.
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.require_paths = ["lib"]
18
18
 
19
+ spec.add_dependency("async-io", "~> 1.1")
19
20
  spec.add_dependency("async-http", "~> 0.3")
20
21
  spec.add_dependency("async-container", "~> 0.1")
21
22
 
@@ -23,7 +24,7 @@ Gem::Specification.new do |spec|
23
24
 
24
25
  spec.add_dependency('samovar', "~> 1.3")
25
26
 
26
- spec.add_development_dependency "async-rspec", "~> 1.1"
27
+ spec.add_development_dependency "async-rspec", "~> 1.2"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.3"
29
30
  spec.add_development_dependency "rspec", "~> 3.6"
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'server'
22
+ require_relative 'verbose'
22
23
 
23
24
  require 'async/container'
24
25
 
@@ -63,9 +64,21 @@ module Falcon
63
64
  end
64
65
  end
65
66
 
66
- def run
67
+ def load_app(verbose)
67
68
  app, options = Rack::Builder.parse_file(@options[:config])
68
69
 
70
+ if verbose
71
+ app = Verbose.new(app)
72
+ end
73
+
74
+ return app, options
75
+ end
76
+
77
+ def run(verbose)
78
+ app, options = load_app(verbose)
79
+
80
+ Async.logger.info "Falcon taking flight! Binding to #{@options[:bind]} [#{container_class} with concurrency: #{@options[:concurrency]}]"
81
+
69
82
  container_class.new(concurrency: @options[:concurrency]) do
70
83
  server = Falcon::Server.new(app, [
71
84
  Async::IO::Endpoint.parse(@options[:bind], reuse_port: true)
@@ -75,8 +88,8 @@ module Falcon
75
88
  end
76
89
  end
77
90
 
78
- def invoke
79
- run
91
+ def invoke(parent)
92
+ run(!parent.quiet?)
80
93
 
81
94
  sleep
82
95
  end
@@ -85,6 +98,12 @@ module Falcon
85
98
  class Top < Samovar::Command
86
99
  self.description = "An asynchronous HTTP client/server toolset."
87
100
 
101
+ options do
102
+ option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
103
+ option '-h/--help', "Print out help information."
104
+ option '-v/--version', "Print out the application version."
105
+ end
106
+
88
107
  nested '<command>',
89
108
  'serve' => Serve
90
109
  # 'get' => Get
@@ -92,12 +111,30 @@ module Falcon
92
111
  # 'head' => Head,
93
112
  # 'put' => Put,
94
113
  # 'delete' => Delete
95
-
114
+
115
+ def verbose?
116
+ @options[:logging] == :verbose
117
+ end
118
+
119
+ def quiet?
120
+ @options[:logging] == :quiet
121
+ end
122
+
96
123
  def invoke(program_name: File.basename($0))
97
- if @command
98
- @command.invoke
124
+ if verbose?
125
+ Async.logger.level = Logger::DEBUG
126
+ elsif quiet?
127
+ Async.logger.level = Logger::WARN
99
128
  else
129
+ Async.logger.level = Logger::INFO
130
+ end
131
+
132
+ if @options[:version]
133
+ puts "falcon v#{Falcon::VERSION}"
134
+ elsif @options[:help] or @command.nil?
100
135
  print_usage(program_name)
136
+ else
137
+ @command.invoke(self)
101
138
  end
102
139
  end
103
140
  end
@@ -0,0 +1,52 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'async/logger'
22
+
23
+ module Falcon
24
+ class Verbose
25
+ def initialize(app, logger = Async.logger)
26
+ @app = app
27
+ @logger = logger
28
+ end
29
+
30
+ def log(start_time, env, response, error)
31
+ duration = Time.now - start_time
32
+
33
+ request_method = env['REQUEST_METHOD']
34
+ request_path = env['PATH_INFO']
35
+
36
+ if response
37
+ status, headers, body = response
38
+ @logger.info "#{request_method} #{request_path} -> #{status}; Content length #{headers.fetch('Content-Length', '-')} bytes; took #{duration} seconds"
39
+ else
40
+ @logger.info "#{request_method} #{request_path} -> #{error}; took #{duration} seconds"
41
+ end
42
+ end
43
+
44
+ def call(env)
45
+ start_time = Time.now
46
+
47
+ response = @app.call(env)
48
+ ensure
49
+ log(start_time, env, response, $!)
50
+ end
51
+ end
52
+ end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Falcon
22
- VERSION = "0.5.0"
22
+ VERSION = "0.6.0"
23
23
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-io
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: async-http
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.1'
89
+ version: '1.2'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.1'
96
+ version: '1.2'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -137,10 +151,14 @@ files:
137
151
  - README.md
138
152
  - Rakefile
139
153
  - bin/falcon
154
+ - examples/sinatra/Gemfile
155
+ - examples/sinatra/Gemfile.lock
156
+ - examples/sinatra/config.ru
140
157
  - falcon.gemspec
141
158
  - lib/falcon.rb
142
159
  - lib/falcon/command.rb
143
160
  - lib/falcon/server.rb
161
+ - lib/falcon/verbose.rb
144
162
  - lib/falcon/version.rb
145
163
  - lib/rack/handler/falcon.rb
146
164
  homepage: https://github.com/socketry/falcon
@@ -162,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
180
  version: '0'
163
181
  requirements: []
164
182
  rubyforge_project:
165
- rubygems_version: 2.6.10
183
+ rubygems_version: 2.6.12
166
184
  signing_key:
167
185
  specification_version: 4
168
186
  summary: ''