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 spaces and untabify request.rb.
Sat Aug 02 06:17:15 -0700 2008
macournoyer (committer)
Sat Aug 02 07:43:14 -0700 2008
commit  d7704d7cd0ea270b002d96ede181244dbe8f5ccb
tree    e807464bf8ed357863d4210f904b0cc4db880bed
parent  2470ab0206716b445c23a1c81eb5f01dff06ad3a
...
5
6
7
8
 
9
10
11
...
13
14
15
16
 
17
18
19
...
24
25
26
27
 
28
29
30
...
32
33
34
35
 
36
37
38
 
39
40
41
 
42
43
44
 
45
46
47
...
49
50
51
52
 
53
54
55
 
56
57
58
 
59
60
61
62
63
64
 
65
66
67
68
69
70
 
71
72
73
74
 
 
75
76
77
78
79
80
81
 
 
82
83
84
...
87
88
89
90
 
91
92
93
94
95
 
96
97
98
99
100
 
101
102
103
...
105
106
107
108
 
109
110
111
...
113
114
115
116
 
117
118
119
120
 
121
122
123
124
 
125
126
127
128
 
129
130
131
132
133
 
 
134
135
136
...
138
139
140
141
 
142
143
144
145
 
 
...
5
6
7
 
8
9
10
11
...
13
14
15
 
16
17
18
19
...
24
25
26
 
27
28
29
30
...
32
33
34
 
35
36
37
 
38
39
40
 
41
42
43
 
44
45
46
47
...
49
50
51
 
52
53
54
 
55
56
57
 
58
59
60
61
62
63
 
64
65
66
67
68
69
 
70
71
72
 
 
73
74
75
76
77
78
79
 
 
80
81
82
83
84
...
87
88
89
 
90
91
92
93
94
 
95
96
97
98
99
 
100
101
102
103
...
105
106
107
 
108
109
110
111
...
113
114
115
 
116
117
118
119
 
120
121
122
123
 
124
125
126
127
 
128
129
130
131
 
 
132
133
134
135
136
...
138
139
140
 
141
142
 
 
143
144
145
0
@@ -5,7 +5,7 @@ module Thin
0
   # Raised when an incoming request is not valid
0
   # and the server can not process it.
0
   class InvalidRequest < IOError; end
0
-  
0
+
0
   # A request sent by the client to the server.
0
   class Request
0
     # Maximum request body size before it is moved out of memory
0
@@ -13,7 +13,7 @@ module Thin
0
     MAX_BODY          = 1024 * (80 + 32)
0
     BODY_TMPFILE      = 'thin-body'.freeze
0
     MAX_HEADER        = 1024 * (80 + 32)
0
-    
0
+
0
     # Freeze some HTTP header names & values
0
     SERVER_SOFTWARE   = 'SERVER_SOFTWARE'.freeze
0
     HTTP_VERSION      = 'HTTP_VERSION'.freeze
0
@@ -24,7 +24,7 @@ module Thin
0
     CONNECTION        = 'HTTP_CONNECTION'.freeze
0
     KEEP_ALIVE_REGEXP = /\bkeep-alive\b/i.freeze
0
     CLOSE_REGEXP      = /\bclose\b/i.freeze
0
-    
0
+
0
     # Freeze some Rack header names
0
     RACK_INPUT        = 'rack.input'.freeze
0
     RACK_VERSION      = 'rack.version'.freeze
0
@@ -32,16 +32,16 @@ module Thin
0
     RACK_MULTITHREAD  = 'rack.multithread'.freeze
0
     RACK_MULTIPROCESS = 'rack.multiprocess'.freeze
0
     RACK_RUN_ONCE     = 'rack.run_once'.freeze
0
-    
0
+
0
     # CGI-like request environment variables
0
     attr_reader :env
0
-    
0
+
0
     # Unparsed data of the request
0
     attr_reader :data
0
-    
0
+
0
     # Request body
0
     attr_reader :body
0
-    
0
+
0
     def initialize
0
       @parser   = HttpParser.new
0
       @data     = ''
0
@@ -49,36 +49,36 @@ module Thin
0
       @body     = StringIO.new
0
       @env      = {
0
         SERVER_SOFTWARE   => SERVER,
0
-        
0
+
0
         # Rack stuff
0
         RACK_INPUT        => @body,
0
-        
0
+
0
         RACK_VERSION      => VERSION::RACK,
0
         RACK_ERRORS       => STDERR,
0
-        
0
+
0
         RACK_MULTITHREAD  => false,
0
         RACK_MULTIPROCESS => false,
0
         RACK_RUN_ONCE     => false
0
       }
0
     end
0
-        
0
+
0
     # Parse a chunk of data into the request environment
0
     # Raises a +InvalidRequest+ if invalid.
0
     # Returns +true+ if the parsing is complete.
0
     def parse(data)
0
       if @parser.finished?  # Header finished, can only be some more body
0
-        body << data        
0
+        body << data
0
       else                  # Parse more header using the super parser
0
         @data << data
0
-        raise InvalidRequest, 'Header longer than allowed' if @data.size > MAX_HEADER 
0
-        
0
+        raise InvalidRequest, 'Header longer than allowed' if @data.size > MAX_HEADER
0
+
0
         @nparsed = @parser.execute(@env, @data, @nparsed)
0
 
0
         # Transfert to a tempfile if body is very big
0
         move_body_to_tempfile if @parser.finished? && content_length > MAX_BODY
0
       end
0
-      
0
-      
0
+
0
+
0
       if finished?   # Check if header and body are complete
0
         @data = nil
0
         @body.rewind
0
@@ -87,17 +87,17 @@ module Thin
0
         false        # Not finished, need more data
0
       end
0
     end
0
-    
0
+
0
     # +true+ if headers and body are finished parsing
0
     def finished?
0
       @parser.finished? && @body.size >= content_length
0
     end
0
-    
0
+
0
     # Expected size of the body
0
     def content_length
0
       @env[CONTENT_LENGTH].to_i
0
     end
0
-    
0
+
0
     # Returns +true+ if the client expect the connection to be persistent.
0
     def persistent?
0
       # Clients and servers SHOULD NOT assume that a persistent connection
0
@@ -105,7 +105,7 @@ module Thin
0
       # signaled. (http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html)
0
       if @env[HTTP_VERSION] == HTTP_1_0
0
         @env[CONNECTION] =~ KEEP_ALIVE_REGEXP
0
-      
0
+
0
       # HTTP/1.1 client intends to maintain a persistent connection unless
0
       # a Connection header including the connection-token "close" was sent
0
       # in the request
0
@@ -113,24 +113,24 @@ module Thin
0
         @env[CONNECTION].nil? || @env[CONNECTION] !~ CLOSE_REGEXP
0
       end
0
     end
0
-    
0
+
0
     def remote_address=(address)
0
       @env[REMOTE_ADDR] = address
0
     end
0
-    
0
+
0
     def forwarded_for
0
       @env[FORWARDED_FOR]
0
     end
0
-    
0
+
0
     def threaded=(value)
0
       @env[RACK_MULTITHREAD] = value
0
     end
0
-    
0
+
0
     # Close any resource used by the request
0
     def close
0
       @body.delete if @body.class == Tempfile
0
-    end    
0
-    
0
+    end
0
+
0
     private
0
       def move_body_to_tempfile
0
         current_body = @body
0
@@ -138,7 +138,7 @@ module Thin
0
         @body = Tempfile.new(BODY_TMPFILE)
0
         @body.binmode
0
         @body << current_body.read
0
-        @env[RACK_INPUT] = @body        
0
+        @env[RACK_INPUT] = @body
0
       end
0
-  end  
0
-end
0
\ No newline at end of file
0
+  end
0
+end

Comments