thin 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,5 +1,12 @@
1
+ == 0.8.1 Rebel Porpoise release
2
+ * [bug] Rescue all types of errors when processing request, fixes #62
3
+ * [bug] Use Swiftiply backend when -y option is specified, fixes #63 and #64
4
+ * Allow passing port as a string in Server.new
5
+ * Define deferred?(env) in your Rack application to set if a request is handled in a
6
+ thread (return true) or not (return false).
7
+
1
8
  == 0.8.0 Dodgy Dentist release
2
- * Fix server crash when header too large.
9
+ * [bug] Fix server crash when header too large.
3
10
  * Add --require (-r) option to require a library, before executing your script.
4
11
  * Rename --rackup short option to -R, warn and load as rackup when file ends with .ru.
5
12
  * List supported adapters in command usage.
@@ -7,7 +14,7 @@
7
14
  * Allow disabling signal handling in Server with :signals => false
8
15
  * Make Server.new arguments more flexible, can now specify any of host, port, app or hash options.
9
16
  * Add --backend option to specified which backend to use, closes #55
10
- * Serve static file only on GET and HEAD requests in Rails adapter, fixes #58
17
+ * [bug] Serve static file only on GET and HEAD requests in Rails adapter, fixes #58
11
18
  * Add threaded option to run server in threaded mode, calling the application in a
12
19
  thread allowing for concurrency in the Rack adapter, closes #46
13
20
  * Guess which adapter to use from directory (chdir option)
@@ -21,14 +21,12 @@ module Thin
21
21
 
22
22
  # Calling the application in a threaded allowing
23
23
  # concurrent processing of requests.
24
- attr_accessor :threaded
24
+ attr_writer :threaded
25
25
 
26
26
  # Get the connection ready to process a request.
27
27
  def post_init
28
28
  @request = Request.new
29
29
  @response = Response.new
30
-
31
- @request.threaded = threaded
32
30
  end
33
31
 
34
32
  # Called when data is received from the client.
@@ -44,9 +42,11 @@ module Thin
44
42
  # Called when all data was received and the request
45
43
  # is ready to be processed.
46
44
  def process
47
- if @threaded
45
+ if threaded?
46
+ @request.threaded = true
48
47
  EventMachine.defer(method(:pre_process), method(:post_process))
49
48
  else
49
+ @request.threaded = false
50
50
  post_process(pre_process)
51
51
  end
52
52
  end
@@ -57,7 +57,7 @@ module Thin
57
57
 
58
58
  # Process the request calling the Rack adapter
59
59
  @app.call(@request.env)
60
- rescue
60
+ rescue Object
61
61
  handle_error
62
62
  terminate_request
63
63
  nil # Signal to post_process that the request could not be processed
@@ -80,7 +80,7 @@ module Thin
80
80
  # If no more request on that same connection, we close it.
81
81
  close_connection_after_writing unless persistent?
82
82
 
83
- rescue
83
+ rescue Object
84
84
  handle_error
85
85
  ensure
86
86
  terminate_request
@@ -121,12 +121,19 @@ module Thin
121
121
  # and ready to be reused for another request.
122
122
  def persistent?
123
123
  @can_persist && @response.persistent?
124
- end
124
+ end
125
+
126
+ # +true+ if <tt>app.call</tt> will be called inside a thread.
127
+ # You can set all requests as threaded setting <tt>Connection#threaded=true</tt>
128
+ # or on a per-request case returning +true+ in <tt>app.deferred?</tt>.
129
+ def threaded?
130
+ @threaded || (@app.respond_to?(:deferred?) && @app.deferred?(@request.env))
131
+ end
125
132
 
126
133
  # IP Address of the remote client.
127
134
  def remote_address
128
135
  @request.forwarded_for || socket_address
129
- rescue
136
+ rescue Object
130
137
  log_error
131
138
  nil
132
139
  end
@@ -35,15 +35,12 @@ module Thin
35
35
  end
36
36
 
37
37
  def start
38
- # Select proper backend
39
- server = case
40
- when @options.has_key?(:backend)
41
- Server.new(@options[:address], @options[:port], :backend => eval(@options[:backend], TOPLEVEL_BINDING))
42
- when @options.has_key?(:socket)
43
- Server.new(@options[:socket])
44
- else
45
- Server.new(@options[:address], @options[:port])
46
- end
38
+ # Constantize backend class
39
+ @options[:backend] = eval(@options[:backend], TOPLEVEL_BINDING) if @options[:backend]
40
+
41
+ server = Server.new(@options[:socket] || @options[:address], # Server detects kind of socket
42
+ @options[:port], # Port ignored on UNIX socket
43
+ @options)
47
44
 
48
45
  # Set options
49
46
  server.pid_file = @options[:pid]
@@ -90,9 +90,9 @@ module Thin
90
90
 
91
91
  args.each do |arg|
92
92
  case arg
93
- when String then host = arg
94
- when Fixnum then port = arg
95
- when Hash then options = arg
93
+ when Fixnum, /^\d+$/ then port = arg.to_i
94
+ when String then host = arg
95
+ when Hash then options = arg
96
96
  else
97
97
  @app = arg if arg.respond_to?(:call)
98
98
  end
@@ -6,11 +6,11 @@ module Thin
6
6
  module VERSION #:nodoc:
7
7
  MAJOR = 0
8
8
  MINOR = 8
9
- TINY = 0
9
+ TINY = 1
10
10
 
11
11
  STRING = [MAJOR, MINOR, TINY].join('.')
12
12
 
13
- CODENAME = 'Dodgy Dentist'
13
+ CODENAME = 'Rebel Porpoise'
14
14
 
15
15
  RACK = [0, 3].freeze # Latest Rack version that was tested
16
16
  end
Binary file
@@ -30,6 +30,16 @@ describe Connection do
30
30
  @connection.process
31
31
  end
32
32
 
33
+ it "should rescue error in process" do
34
+ @connection.app.should_receive(:call).and_raise(StandardError)
35
+ @connection.process
36
+ end
37
+
38
+ it "should rescue Timeout error in process" do
39
+ @connection.app.should_receive(:call).and_raise(Timeout::Error.new("timeout error not rescued"))
40
+ @connection.process
41
+ end
42
+
33
43
  it "should return HTTP_X_FORWARDED_FOR as remote_address" do
34
44
  @connection.request.env['HTTP_X_FORWARDED_FOR'] = '1.2.3.4'
35
45
  @connection.remote_address.should == '1.2.3.4'
@@ -71,9 +81,25 @@ describe Connection do
71
81
  end
72
82
 
73
83
  it "should set request env as rack.multithread" do
84
+ EventMachine.should_receive(:defer)
85
+
74
86
  @connection.threaded = true
75
- @connection.post_init
87
+ @connection.process
76
88
 
77
89
  @connection.request.env["rack.multithread"].should == true
78
90
  end
91
+
92
+ it "should set as threaded when app.deferred? is true" do
93
+ @connection.app.should_receive(:deferred?).and_return(true)
94
+ @connection.should be_threaded
95
+ end
96
+
97
+ it "should not set as threaded when app.deferred? is false" do
98
+ @connection.app.should_receive(:deferred?).and_return(false)
99
+ @connection.should_not be_threaded
100
+ end
101
+
102
+ it "should not set as threaded when app do not respond to deferred?" do
103
+ @connection.should_not be_threaded
104
+ end
79
105
  end
@@ -16,7 +16,7 @@ describe Controller, 'start' do
16
16
  @server = OpenStruct.new
17
17
  @adapter = OpenStruct.new
18
18
 
19
- Server.should_receive(:new).with('0.0.0.0', 3000).and_return(@server)
19
+ Server.should_receive(:new).with('0.0.0.0', 3000, @controller.options).and_return(@server)
20
20
  @server.should_receive(:config)
21
21
  Rack::Adapter::Rails.stub!(:new).and_return(@adapter)
22
22
  end
@@ -81,6 +81,14 @@ describe Server, "initialization" do
81
81
  server.backend.should be_kind_of(Thin::Backends::SwiftiplyClient)
82
82
  end
83
83
 
84
+ it "should set port as string" do
85
+ app = proc {}
86
+ server = Server.new('192.168.1.1', '8080')
87
+
88
+ server.host.should == '192.168.1.1'
89
+ server.port.should == 8080
90
+ end
91
+
84
92
  it "should not register signals w/ :signals => false" do
85
93
  Server.should_not_receive(:setup_signals)
86
94
  Server.new(:signals => false)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-Andre Cournoyer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-06 00:00:00 -04:00
12
+ date: 2008-04-19 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,6 @@ files:
97
97
  - lib/thin/statuses.rb
98
98
  - lib/thin/version.rb
99
99
  - lib/thin.rb
100
- - lib/thin_backend.bundle
101
100
  - lib/thin_parser.bundle
102
101
  - spec/backends
103
102
  - spec/backends/swiftiply_client_spec.rb
Binary file