reifier 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/rack/handler/reifier.rb +6 -0
- data/lib/reifier/response.rb +22 -20
- data/lib/reifier/server.rb +18 -14
- data/lib/reifier/version.rb +1 -1
- data/reifier.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9851d78945b3c347db66a2abaf1226e042250e8
|
4
|
+
data.tar.gz: e3995204dda21f2d7b920f62f5015af09fef0b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd6c52d68405d750ba5ea58b0bb8fbfb919479113dedea8896f1b459a586b1564a42fb0e5e6575e3505eaf19ce95b29d7abd36e13307b47684366c986be2b5c7
|
7
|
+
data.tar.gz: 53015621be965b1e53ae5b499fb1728a320617850136e9d8e2d5f246a15de6db3870898e6ca2f53bad026b5abcdf90863a39f31fa877d53c5c588eb185d955a2
|
data/README.md
CHANGED
@@ -28,6 +28,12 @@ Use it through rackup:
|
|
28
28
|
|
29
29
|
$ rackup -s reifier
|
30
30
|
|
31
|
+
## Available Options
|
32
|
+
|
33
|
+
You can adapt the ThreadPool sized with following option:
|
34
|
+
|
35
|
+
$ rackup -s reifier -O Threads=16
|
36
|
+
|
31
37
|
## Development
|
32
38
|
|
33
39
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -38,7 +44,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
38
44
|
|
39
45
|
Bug reports and pull requests are welcome on GitHub at https://github.com/tak1n/reifier.
|
40
46
|
|
41
|
-
|
42
47
|
## License
|
43
48
|
|
44
49
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/rack/handler/reifier.rb
CHANGED
data/lib/reifier/response.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
module Reifier
|
2
2
|
class Response
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :status, :headers, :body, :protocol
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@response = ''
|
7
|
+
end
|
4
8
|
|
5
9
|
def handle(socket)
|
6
|
-
handle_request_line
|
7
|
-
handle_headers
|
8
|
-
handle_body
|
10
|
+
handle_request_line
|
11
|
+
handle_headers
|
12
|
+
handle_body
|
13
|
+
|
14
|
+
socket.write @response
|
15
|
+
socket.close
|
9
16
|
end
|
10
17
|
|
11
18
|
def <<(rack_return)
|
@@ -16,31 +23,26 @@ module Reifier
|
|
16
23
|
|
17
24
|
private
|
18
25
|
|
19
|
-
def handle_request_line
|
20
|
-
|
26
|
+
def handle_request_line
|
27
|
+
@response << "#{@protocol} #{@status} #{HTTP_STATUS_CODES[@status]}" + CRLF
|
21
28
|
end
|
22
29
|
|
23
|
-
def handle_headers
|
24
|
-
headers = ''
|
30
|
+
def handle_headers
|
25
31
|
@headers.each do |k, v|
|
26
|
-
|
32
|
+
@response << "#{k}: #{v}" + CRLF
|
27
33
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
socket.write headers
|
34
|
+
@response << 'Connection: close' + CRLF
|
35
|
+
@response << CRLF
|
32
36
|
end
|
33
37
|
|
34
|
-
def handle_body
|
35
|
-
body = ''
|
38
|
+
def handle_body
|
36
39
|
@body.each do |chunk|
|
37
|
-
|
40
|
+
@response << chunk
|
38
41
|
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
socket.close
|
43
|
+
@response << CRLF
|
44
|
+
ensure
|
45
|
+
@body.close if @body.respond_to? :close
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
data/lib/reifier/server.rb
CHANGED
@@ -13,16 +13,20 @@ module Reifier
|
|
13
13
|
end
|
14
14
|
|
15
15
|
server = TCPServer.new(@options[:Host], @options[:Port])
|
16
|
-
|
16
|
+
|
17
|
+
threads = @options[:Threads] || 5
|
18
|
+
pool = Concurrent::FixedThreadPool.new(@options[:Threads] || 5)
|
17
19
|
|
18
20
|
puts "# Environment: #{@options[:environment]}"
|
19
21
|
puts "# Listening on tcp://#{@options[:Host]}:#{@options[:Port]}"
|
20
22
|
puts "# PID: #{Process.pid}"
|
23
|
+
puts "# Number of Threads used: #{threads}"
|
21
24
|
|
22
25
|
loop do
|
23
26
|
socket = server.accept
|
24
27
|
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
25
28
|
|
29
|
+
# Thread.new do
|
26
30
|
pool.post do
|
27
31
|
begin
|
28
32
|
request = Request.new(@options)
|
@@ -30,22 +34,14 @@ module Reifier
|
|
30
34
|
|
31
35
|
request.handle(socket)
|
32
36
|
|
33
|
-
response.
|
34
|
-
response.request_uri = request.request_uri
|
35
|
-
response.protocol = request.protocol
|
36
|
-
|
37
|
+
response.protocol = request.protocol
|
37
38
|
response << @app.call(request.rack_env)
|
38
39
|
|
39
40
|
response.handle(socket)
|
40
41
|
|
41
|
-
|
42
|
-
rescue
|
43
|
-
|
44
|
-
rescue HTTPParseError
|
45
|
-
puts 'Request Line must include HTTP (HTTPS enabled?)'
|
46
|
-
rescue Errno::EPIPE
|
47
|
-
puts 'Writing to client failed :|'
|
48
|
-
ensure
|
42
|
+
log_request request, response if development?
|
43
|
+
rescue Exception => e
|
44
|
+
log "\nError: #{e.class}\nMessage: #{e.message}\n\nBacktrace:\n\t#{e.backtrace.join("\n\t")}" if development?
|
49
45
|
socket.close
|
50
46
|
end
|
51
47
|
end
|
@@ -54,7 +50,15 @@ module Reifier
|
|
54
50
|
|
55
51
|
private
|
56
52
|
|
57
|
-
def
|
53
|
+
def development?
|
54
|
+
@options[:environment] == 'development'
|
55
|
+
end
|
56
|
+
|
57
|
+
def log(message)
|
58
|
+
puts "[#{Time.now}] #{message}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def log_request(request, response)
|
58
62
|
puts "[#{Time.now}] \"#{request.request_method} #{request.request_path} #{request.protocol}\" #{response.status}"
|
59
63
|
end
|
60
64
|
end
|
data/lib/reifier/version.rb
CHANGED
data/reifier.gemspec
CHANGED
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'pry', '~> 0.10'
|
36
36
|
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
|
37
37
|
spec.add_development_dependency 'rubocop', '~> 0.37'
|
38
|
-
spec.add_development_dependency 'rack'
|
38
|
+
spec.add_development_dependency 'rack', '~> 2.0.0.alpha'
|
39
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benny Klotz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: rack
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 2.0.0.alpha
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 2.0.0.alpha
|
125
125
|
description: A rack app server written in pure ruby
|
126
126
|
email:
|
127
127
|
- benny.klotz92@gmail.com
|