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