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:
Convert some tabs to spaces
macournoyer (author)
Sun Jan 20 08:14:47 -0800 2008
commit  b698fe8f2512a85ed95bfa2922d7d1dc77f1e83c
tree    3d607385439f6d57a5bc0e62eb07f0d6f7d42ffe
parent  6aa930c5f5f05f200d2861ced10bb1e3f33149b4
...
13
14
15
16
 
17
18
19
...
25
26
27
28
 
29
30
31
...
13
14
15
 
16
17
18
19
...
25
26
27
 
28
29
30
31
0
@@ -13,7 +13,7 @@
0
     
0
     def receive_data(data)
0
       trace { data }
0
- process if @request.parse(data)
0
+ process if @request.parse(data)
0
     rescue InvalidRequest => e
0
       log "Invalid request"
0
       log_error e
0
@@ -25,7 +25,7 @@
0
       
0
       # Add client info to the request env
0
       env[Request::REMOTE_ADDR] = env[Request::FORWARDED_FOR] || Socket.unpack_sockaddr_in(get_peername)[1]
0
-
0
+
0
       # Process the request
0
       @response.status, @response.headers, @response.body = @app.call(env)
0
       
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@
0
       @sent = {}
0
       @items = []
0
     end
0
-
0
+
0
     def []=(key, value)
0
       if @sent.has_key?(key) && !ALLOWED_DUPLICATES.include?(key)
0
         # If we don't allow duplicate for that field
...
12
13
14
15
 
16
17
18
19
20
21
 
22
23
24
25
...
61
62
63
64
65
 
 
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
 
 
 
 
 
 
 
 
 
 
 
 
80
81
82
83
...
88
89
90
 
91
92
93
94
95
96
97
 
 
 
 
98
99
100
...
12
13
14
 
15
16
17
18
19
20
 
21
22
23
24
25
...
61
62
63
 
 
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
...
88
89
90
91
92
93
94
 
 
 
 
95
96
97
98
99
100
101
0
@@ -12,13 +12,13 @@
0
     # and into a tempfile for reading.
0
     MAX_BODY = 1024 * (80 + 32)
0
     BODY_TMPFILE = 'thin-body'.freeze
0
-
0
+
0
     # Freeze some HTTP header names
0
     SERVER_SOFTWARE = 'SERVER_SOFTWARE'.freeze
0
     REMOTE_ADDR = 'REMOTE_ADDR'.freeze
0
     FORWARDED_FOR = 'HTTP_X_FORWARDED_FOR'.freeze
0
     CONTENT_LENGTH = 'CONTENT_LENGTH'.freeze
0
-
0
+
0
     # Freeze some Rack header names
0
     RACK_INPUT = 'rack.input'.freeze
0
     RACK_VERSION = 'rack.version'.freeze
0
0
@@ -61,22 +61,22 @@
0
     # Returns +true+ if the parsing is complete.
0
     def parse(data)
0
       @data << data
0
-
0
- if @parser.finished? # Header finished, can only be some more body
0
+
0
+ if @parser.finished? # Header finished, can only be some more body
0
         body << data
0
- else # Parse more header using the super parser
0
- @nparsed = @parser.execute(@env, @data, @nparsed)
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
- # Check if header and body are complete
0
- if @parser.finished? && @body.size >= content_length
0
- @body.rewind
0
- return true # Request is fully parsed
0
- end
0
-
0
- false # Not finished, need more data
0
+ else # Parse more header using the super parser
0
+ @nparsed = @parser.execute(@env, @data, @nparsed)
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
+ # Check if header and body are complete
0
+ if @parser.finished? && @body.size >= content_length
0
+ @body.rewind
0
+ return true # Request is fully parsed
0
+ end
0
+
0
+ false # Not finished, need more data
0
     end
0
     
0
     # Expected size of the body
0
0
@@ -88,13 +88,14 @@
0
       @body.close if @body === Tempfile
0
     end
0
     
0
+
0
     private
0
       def move_body_to_tempfile
0
         current_body = @body
0
- @body = Tempfile.new(BODY_TMPFILE)
0
- @body.binmode
0
- @body << current_body unless current_body.size.zero?
0
- @env[RACK_INPUT] = @body
0
+ @body = Tempfile.new(BODY_TMPFILE)
0
+ @body.binmode
0
+ @body << current_body unless current_body.size.zero?
0
+ @env[RACK_INPUT] = @body
0
       end
0
   end
0
 end
...
47
48
49
50
 
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
...
47
48
49
 
50
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -47,23 +47,23 @@
0
     # Start listening for connections
0
     def listen!
0
       trap('INT') { stop }
0
- trap('TERM') { stop! }
0
+ trap('TERM') { stop! }
0
       
0
       # See http://rubyeventmachine.com/pub/rdoc/files/EPOLL.html
0
       EventMachine.epoll
0
-
0
- EventMachine.run do
0
- begin
0
- log ">> Listening on #{@host}:#{@port}, CTRL+C to stop"
0
- EventMachine.start_server(@host, @port, Connection) do |connection|
0
- connection.comm_inactivity_timeout = @timeout
0
- connection.app = @app
0
- connection.silent = @silent
0
- end
0
- rescue StopServer
0
- EventMachine.stop_event_loop
0
- end
0
- end
0
+
0
+ EventMachine.run do
0
+ begin
0
+ log ">> Listening on #{@host}:#{@port}, CTRL+C to stop"
0
+ EventMachine.start_server(@host, @port, Connection) do |connection|
0
+ connection.comm_inactivity_timeout = @timeout
0
+ connection.app = @app
0
+ connection.silent = @silent
0
+ end
0
+ rescue StopServer
0
+ EventMachine.stop_event_loop
0
+ end
0
+ end
0
     end
0
     
0
     
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@
0
     MAJOR = 0
0
     MINOR = 5
0
     TINY = 4
0
-
0
+
0
     STRING = [MAJOR, MINOR, TINY].join('.')
0
     
0
     CODENAME = 'Flying Mustard'

Comments

    No one has commented yet.