public
Rubygem
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Click here to lend your support to: thin and make a donation at www.pledgie.com !
Strip trailing whitespace and untabify connection.rb.
Sat Aug 02 06:17:49 -0700 2008
macournoyer (committer)
Sat Aug 02 07:43:14 -0700 2008
commit  692307873c71858036a810d839a61f3e79ac6ea7
tree    520bdcde58b36dd4ee51848c840e8c5bfad07032
parent  d7704d7cd0ea270b002d96ede181244dbe8f5ccb
...
10
11
12
13
 
14
15
16
 
17
18
19
 
20
21
22
 
23
24
25
 
26
27
28
29
 
30
31
32
33
34
35
 
36
37
38
...
42
43
44
45
 
46
47
48
...
54
55
56
57
 
58
59
60
61
 
62
63
64
...
66
67
68
69
 
70
71
72
 
73
74
75
 
76
77
78
79
80
81
 
82
83
84
85
86
87
 
88
89
90
 
91
92
93
...
108
109
110
111
 
112
113
114
115
116
 
117
118
119
120
121
122
 
123
124
125
...
135
136
137
138
 
139
140
141
142
143
144
145
 
146
147
148
...
150
151
152
153
 
154
155
156
157
158
159
160
 
161
162
163
...
167
168
169
170
 
171
172
173
...
10
11
12
 
13
14
15
 
16
17
18
 
19
20
21
 
22
23
24
 
25
26
27
28
 
29
30
31
32
33
34
 
35
36
37
38
...
42
43
44
 
45
46
47
48
...
54
55
56
 
57
58
59
60
 
61
62
63
64
...
66
67
68
 
69
70
71
 
72
73
74
 
75
76
77
78
79
80
 
81
82
83
84
85
86
 
87
88
89
 
90
91
92
93
...
108
109
110
 
111
112
113
114
115
 
116
117
118
119
120
121
 
122
123
124
125
...
135
136
137
 
138
139
140
141
142
143
144
 
145
146
147
148
...
150
151
152
 
153
154
155
156
157
158
159
 
160
161
162
163
...
167
168
169
 
170
171
172
173
0
@@ -10,29 +10,29 @@ module Thin
0
     CHUNKED_REGEXP    = /\bchunked\b/i.freeze
0
 
0
     include Logging
0
-    
0
+
0
     # Rack application (adapter) served by this connection.
0
     attr_accessor :app
0
-    
0
+
0
     # Backend to the server
0
     attr_accessor :backend
0
-    
0
+
0
     # Current request served by the connection
0
     attr_accessor :request
0
-    
0
+
0
     # Next response sent through the connection
0
     attr_accessor :response
0
-    
0
+
0
     # Calling the application in a threaded allowing
0
     # concurrent processing of requests.
0
     attr_writer :threaded
0
-    
0
+
0
     # Get the connection ready to process a request.
0
     def post_init
0
       @request  = Request.new
0
       @response = Response.new
0
     end
0
-    
0
+
0
     # Called when data is received from the client.
0
     def receive_data(data)
0
       trace { data }
0
@@ -42,7 +42,7 @@ module Thin
0
       log_error e
0
       close_connection
0
     end
0
-    
0
+
0
     # Called when all data was received and the request
0
     # is ready to be processed.
0
     def process
0
@@ -54,11 +54,11 @@ module Thin
0
         post_process(pre_process)
0
       end
0
     end
0
-    
0
+
0
     def pre_process
0
       # Add client info to the request env
0
       @request.remote_address = remote_address
0
-      
0
+
0
       # Process the request calling the Rack adapter
0
       @app.call(@request.env)
0
     rescue Exception
0
@@ -66,28 +66,28 @@ module Thin
0
       terminate_request
0
       nil # Signal to post_process that the request could not be processed
0
     end
0
-    
0
+
0
     def post_process(result)
0
       return unless result
0
-      
0
+
0
       # Set the Content-Length header if possible
0
       set_content_length(result) if need_content_length?(result)
0
-      
0
+
0
       @response.status, @response.headers, @response.body = result
0
 
0
       log "!! Rack application returned nil body. Probably you wanted it to be an empty string?" if @response.body.nil?
0
       # Make the response persistent if requested by the client
0
       @response.persistent! if @request.persistent?
0
-      
0
+
0
       # Send the response
0
       @response.each do |chunk|
0
         trace { chunk }
0
         send_data chunk
0
       end
0
-      
0
+
0
       # If no more request on that same connection, we close it.
0
       close_connection_after_writing unless persistent?
0
-      
0
+
0
     rescue Exception
0
       handle_error
0
     ensure
0
@@ -108,18 +108,18 @@ module Thin
0
     def terminate_request
0
       @request.close  rescue nil
0
       @response.close rescue nil
0
-      
0
+
0
       # Prepare the connection for another request if the client
0
       # supports HTTP pipelining (persistent connection).
0
       post_init if persistent?
0
     end
0
-    
0
+
0
     # Called when the connection is unbinded from the socket
0
     # and can no longer be used to process requests.
0
     def unbind
0
       @backend.connection_finished(self)
0
     end
0
-    
0
+
0
     # Allows this connection to be persistent.
0
     def can_persist!
0
       @can_persist = true
0
@@ -135,14 +135,14 @@ module Thin
0
     def persistent?
0
       @can_persist && @response.persistent?
0
     end
0
-    
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
+
0
     # IP Address of the remote client.
0
     def remote_address
0
       @request.forwarded_for || socket_address
0
@@ -150,14 +150,14 @@ module Thin
0
       log_error
0
       nil
0
     end
0
-    
0
+
0
     protected
0
 
0
       # Returns IP address of peer as a string.
0
       def socket_address
0
         Socket.unpack_sockaddr_in(get_peername)[1]
0
       end
0
-      
0
+
0
     private
0
       def need_content_length?(result)
0
         status, headers, body = result
0
@@ -167,7 +167,7 @@ module Thin
0
         return false unless body.kind_of?(String) || body.kind_of?(Array)
0
         true
0
       end
0
-      
0
+
0
       def set_content_length(result)
0
         headers, body = result[1..2]
0
         case body

Comments