diff --git a/requests/src/requests/Model.scala b/requests/src/requests/Model.scala index 797500c..4d7c679 100644 --- a/requests/src/requests/Model.scala +++ b/requests/src/requests/Model.scala @@ -132,6 +132,9 @@ object RequestBlob{ partBytes.foreach { case(name, filename, part) => writeBytes(pref + boundary + crlf) + part.data.headers.foreach { case (headerName, headerValue) => + writeBytes(s"$headerName: $headerValue$crlf") + } writeBytes(ContentDisposition) out.write(name) if (filename.nonEmpty){ diff --git a/requests/test/resources/license.zip b/requests/test/resources/license.zip new file mode 100644 index 0000000..0976494 Binary files /dev/null and b/requests/test/resources/license.zip differ diff --git a/requests/test/src/requests/ModelTests.scala b/requests/test/src/requests/ModelTests.scala new file mode 100644 index 0000000..4a4982d --- /dev/null +++ b/requests/test/src/requests/ModelTests.scala @@ -0,0 +1,47 @@ +package requests + +import java.io.ByteArrayOutputStream +import java.io.File +import java.nio.file.{FileSystems, Path} + +import utest._ + +object ModelTests extends TestSuite{ + val tests = Tests { + test("multipart file uploads should contain application/octet-stream content type") { + val path = getClass.getResource("/license.zip").getPath + val file = new File(path) + val nioPath = FileSystems.getDefault.getPath(path) + val fileKey = "fileKey" + val fileName = "fileName" + + val javaFileMultipart = MultiPart( + MultiItem( + fileKey, + file, + fileName + ) + ) + + val nioPathMultipart = MultiPart( + MultiItem( + fileKey, + nioPath, + fileName + ) + ) + + val javaFileOutputStream = new ByteArrayOutputStream() + val nioPathOutputStream = new ByteArrayOutputStream() + + javaFileMultipart.write(javaFileOutputStream) + nioPathMultipart.write(nioPathOutputStream) + + val javaFileString = new String(javaFileOutputStream.toByteArray) + val nioPathString = new String(nioPathOutputStream.toByteArray) + + assert(javaFileString.contains("Content-Type: application/octet-stream")) + assert(nioPathString.contains("Content-Type: application/octet-stream")) + } + } +}