# File lib/mongrel.rb, line 196
196:     def initialize(params, socket, dispatchers)
197:       @params = params
198:       @socket = socket
199:       @dispatchers = dispatchers
200:       content_length = @params[Const::CONTENT_LENGTH].to_i
201:       remain = content_length - @params.http_body.length
202:       
203:       # tell all dispatchers the request has begun
204:       @dispatchers.each do |dispatcher|
205:         dispatcher.request_begins(@params) 
206:       end unless @dispatchers.nil? || @dispatchers.empty?
207: 
208:       # Some clients (like FF1.0) report 0 for body and then send a body.  This will probably truncate them but at least the request goes through usually.
209:       if remain <= 0
210:         # we've got everything, pack it up
211:         @body = StringIO.new
212:         @body.write @params.http_body
213:         update_request_progress(0, content_length)
214:       elsif remain > 0
215:         # must read more data to complete body
216:         if remain > Const::MAX_BODY
217:           # huge body, put it in a tempfile
218:           @body = Tempfile.new(Const::MONGREL_TMP_BASE)
219:           @body.binmode
220:         else
221:           # small body, just use that
222:           @body = StringIO.new 
223:         end
224: 
225:         @body.write @params.http_body
226:         read_body(remain, content_length)
227:       end
228: 
229:       @body.rewind if @body
230:     end