Skip to content

Commit 2f4dd61

Browse files
committed
Fix multi-files multipart requests for streaming backends
1 parent 344989d commit 2f4dd61

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

core/src/main/scalajvm/sttp/client4/internal/httpclient/MultipartBodyBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ trait StreamMultipartBodyBuilder[BinaryStream, F[_]] extends MultipartBodyBuilde
8787
val encodedHeaders = byteArrayToStream(encodeHeaders(partHeaders, boundary))
8888
val endPartBytes = byteArrayToStream(CRLFBytes)
8989
val headersWithContent = concatStreams(encodedHeaders, fileToStream(f.toFile))
90-
concatStreams(headersWithContent, endPartBytes)
90+
concatStreams(accumulatedStream, concatStreams(headersWithContent, endPartBytes))
9191
}
9292
case StringBody(b, e, _) if e.equalsIgnoreCase(Utf8) =>
9393
concatBytesToStream(accumulatedStream, encodeString(b, partHeaders, boundary))

core/src/test/scalajvm/sttp/client4/testing/HttpTestExtensions.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,27 @@ trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] =>
357357
req.send(backend).toFuture().map(resp => resp.body should be(Right(s"p1=$testBody (test.txt)")))
358358
}
359359
}
360+
361+
"send a multipart message with two files" in {
362+
withTemporaryFile(Some("file1:peach mario".getBytes())) { f1 =>
363+
withTemporaryFile(Some("file2:daisy luigi".getBytes())) { f2 =>
364+
println("START " + f1 + " " + f2)
365+
mp
366+
.multipartBody(
367+
multipartFile("file1", f1).fileName("file1.txt"),
368+
multipartFile("file2", f2).fileName("file2.txt")
369+
)
370+
.response(asStringAlways)
371+
.send(backend)
372+
.toFuture()
373+
.map { r =>
374+
r.code shouldBe StatusCode.Ok
375+
r.body should include("file1:peach mario")
376+
r.body should include("file2:daisy luigi")
377+
}
378+
}
379+
}
380+
}
360381
}
361382
}
362383

0 commit comments

Comments
 (0)