--- C:\Documents and Settings\lperon\Bureau\TestMultipartPost.java Tue Nov 08 10:59:32 2005 +++ C:\Documents and Settings\lperon\Bureau\commons-httpclient-3.0-rc4\src\test\org\apache\commons\httpclient\TestMultipartPost.java Tue Nov 08 10:50:57 2005 @@ -40,6 +40,7 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource; import org.apache.commons.httpclient.methods.multipart.FilePart; +import org.apache.commons.httpclient.methods.multipart.InputStreamPartSource; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; @@ -105,6 +106,35 @@ assertTrue(body.indexOf("Hello") >= 0); } + /** + * Test that the body consisting of a file part of unknown length can be posted. + */ + public void testPostFilePartUnknownLength() throws Exception { + + this.server.setHttpService(new EchoService()); + + PostMethod method = new PostMethod(); + byte[] content = "Hello".getBytes(); + MultipartRequestEntity entity = new MultipartRequestEntity( + new Part[] { + new FilePart( + "param1", + new InputStreamPartSource("filename.txt", new ByteArrayInputStream(content)), + "text/plain", + "ISO-8859-1") }, + method.getParams()); + method.setRequestEntity(entity); + + client.executeMethod(method); + + assertEquals(200,method.getStatusCode()); + String body = method.getResponseBodyAsString(); + assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0); + assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0); + assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0); + assertTrue(body.indexOf("Hello") >= 0); + } }