public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Define deferred?(env) in your Rack application to set if a request is 
handled in a thread (return true) or not (return false).
macournoyer (author)
Tue Apr 08 17:41:50 -0700 2008
commit  b02c717f59378f71f11469d2698d96e8a7d197c4
tree    caf1fa2a1a7336cdb614de1ceb2fdfe8149e99ca
parent  77b0f725c399baf145a3631296edcfd60df839a4
...
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
0
@@ -1,3 +1,7 @@
0
+== 0.8.1 Rebel Porpoise release
0
+ * Define deferred?(env) in your Rack application to set if a request is handled in a
0
+   thread (return true) or not (return false).
0
+
0
 == 0.8.0 Dodgy Dentist release
0
  * Fix server crash when header too large.
0
  * Add --require (-r) option to require a library, before executing your script.
...
21
22
23
24
 
25
26
27
28
29
30
31
32
33
34
...
44
45
46
47
 
48
49
50
...
54
55
56
 
57
58
59
...
121
122
123
124
 
 
 
 
 
 
 
 
125
126
127
...
21
22
23
 
24
25
26
27
28
29
 
 
30
31
32
...
42
43
44
 
45
46
47
48
...
52
53
54
55
56
57
58
...
120
121
122
 
123
124
125
126
127
128
129
130
131
132
133
0
@@ -21,14 +21,12 @@ module Thin
0
     
0
     # Calling the application in a threaded allowing
0
     # concurrent processing of requests.
0
- attr_accessor :threaded
0
+ attr_writer :threaded
0
     
0
     # Get the connection ready to process a request.
0
     def post_init
0
       @request = Request.new
0
       @response = Response.new
0
-
0
- @request.threaded = threaded
0
     end
0
     
0
     # Called when data is received from the client.
0
@@ -44,7 +42,7 @@ module Thin
0
     # Called when all data was received and the request
0
     # is ready to be processed.
0
     def process
0
- if @threaded
0
+ if threaded?
0
         EventMachine.defer(method(:pre_process), method(:post_process))
0
       else
0
         post_process(pre_process)
0
@@ -54,6 +52,7 @@ module Thin
0
     def pre_process
0
       # Add client info to the request env
0
       @request.remote_address = remote_address
0
+ @request.threaded = threaded?
0
       
0
       # Process the request calling the Rack adapter
0
       @app.call(@request.env)
0
@@ -121,7 +120,14 @@ module Thin
0
     # and ready to be reused for another request.
0
     def persistent?
0
       @can_persist && @response.persistent?
0
- end
0
+ end
0
+
0
+ # +true+ if <tt>app.call</tt> will be called inside a thread.
0
+ # You can set all requests as threaded setting <tt>Connection#threaded=true</tt>
0
+ # or on a per-request case returning +true+ in <tt>app.deferred?</tt>.
0
+ def threaded?
0
+ @threaded || (@app.respond_to?(:deferred?) && @app.deferred?(@request.env))
0
+ end
0
     
0
     # IP Address of the remote client.
0
     def remote_address
...
6
7
8
9
 
10
11
12
13
 
14
15
16
...
6
7
8
 
9
10
11
12
 
13
14
15
16
0
@@ -6,11 +6,11 @@ module Thin
0
   module VERSION #:nodoc:
0
     MAJOR = 0
0
     MINOR = 8
0
- TINY = 0
0
+ TINY = 1
0
     
0
     STRING = [MAJOR, MINOR, TINY].join('.')
0
     
0
- CODENAME = 'Dodgy Dentist'
0
+ CODENAME = 'Rebel Porpoise'
0
     
0
     RACK = [0, 3].freeze # Latest Rack version that was tested
0
   end
...
72
73
74
75
 
76
77
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
80
...
72
73
74
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
0
@@ -72,8 +72,22 @@ describe Connection do
0
   
0
   it "should set request env as rack.multithread" do
0
     @connection.threaded = true
0
- @connection.post_init
0
+ @connection.pre_process
0
     
0
     @connection.request.env["rack.multithread"].should == true
0
   end
0
+
0
+ it "should set as threaded when app.deferred? is true" do
0
+ @connection.app.should_receive(:deferred?).and_return(true)
0
+ @connection.should be_threaded
0
+ end
0
+
0
+ it "should not set as threaded when app.deferred? is false" do
0
+ @connection.app.should_receive(:deferred?).and_return(false)
0
+ @connection.should_not be_threaded
0
+ end
0
+
0
+ it "should not set as threaded when app do not respond to deferred?" do
0
+ @connection.should_not be_threaded
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.