[PATCH] Make the FTP ioslave emit mime-type of the content before actually reading it
Review Request #101149 - Created April 18, 2011 and submitted
The attached patch changes the ftpGet function such that it emits the mime-type of the content it is about to read, before starting to read it. That way kio_ftp will work correctly if and when it is put on hold to be reused from another application. Note that the patch uses QIODevice::peek to achieve this goal.
Maybe this should be "while we haven't read 1024 bytes", but of course the file could be smaller than that so it would have to check for that too. What I mean is: I assume peek() doesn't wait, so if the first packet we get is 48 bytes, we have only 48 bytes. Don't know if this is a real problem in practice though, feel free to ignore this comment.
If m_size is UnknownSize and the file is less than 1024 bytes, this code is going to hit the timeout, waiting for data to come in, that will never come in. I think that once waitForReadyRead was called once, the loop should break (after peeking, of course), if m_size==Unknown.
Are you sure that peek() is cumulative? I.e. that peek(100) + peek(100) doesn't give you the same data twice? I thought it would, since it "rewinds" after giving you the data.