Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: content type header not present in multipart item #154

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requests/src/requests/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Binary file added requests/test/resources/license.zip
Binary file not shown.
47 changes: 47 additions & 0 deletions requests/test/src/requests/ModelTests.scala
Original file line number Diff line number Diff line change
@@ -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"))
}
}
}
Loading