194: def initialize(params, initial_body, socket)
195: @params = params
196: @socket = socket
197:
198: clen = params[Const::CONTENT_LENGTH].to_i - initial_body.length
199:
200: if clen > Const::MAX_BODY
201: @body = Tempfile.new(Const::MONGREL_TMP_BASE)
202: @body.binmode
203: else
204: @body = StringIO.new
205: end
206:
207: begin
208: @body.write(initial_body)
209:
210:
211: clen -= @body.write(@socket.read(clen % Const::CHUNK_SIZE))
212:
213:
214: while clen > 0
215: data = @socket.read(Const::CHUNK_SIZE)
216:
217: raise "Socket closed or read failure" if not data or data.length != Const::CHUNK_SIZE
218: clen -= @body.write(data)
219:
220: end
221:
222:
223: @body.rewind
224: rescue Object
225:
226: STDERR.puts "Error reading request: #$!"
227: @body.delete if @body.class == Tempfile
228: @body = nil
229: end
230: end