@@ -10,7 +10,7 @@ import org.apache.pekko.http.scaladsl.server.Route
1010import org .apache .pekko .http .scaladsl .server .directives .FileInfo
1111import org .apache .pekko .http .scaladsl .unmarshalling .Unmarshal
1212import org .apache .pekko .stream .RestartSettings
13- import org .apache .pekko .stream .scaladsl .{Compression , FileIO , RestartSource , Sink , Source }
13+ import org .apache .pekko .stream .scaladsl .{FileIO , RestartSource , Sink , Source }
1414import spray .json .{DefaultJsonProtocol , RootJsonFormat }
1515
1616import java .io .File
@@ -45,9 +45,7 @@ trait JsonProtocol extends DefaultJsonProtocol with SprayJsonSupport {
4545 * Added:
4646 * - Retry on upload/download
4747 * Doc: https://blog.colinbreck.com/backoff-and-retry-error-handling-for-akka-streams
48- * - On the fly gzip compression on upload and gunzip decompression on download
49- * Doc: https://doc.akka.io/docs/akka/current/stream/stream-cookbook.html#dealing-with-compressed-data-streams
50- * - Browser client for manual upload of uncompressed files
48+ * - Browser client for manual upload
5149 *
5250 * To prove that the streaming works:
5351 * - Replace testfile.jpg with a large file, eg 63MB.pdf
@@ -65,7 +63,7 @@ object HttpFileEcho extends App with JsonProtocol {
6563 val chuckSizeBytes = 100 * 1024 // to handle large files
6664
6765 server(address, port)
68- (1 to 5 ).par.foreach(each => roundtripClient(each, address, port))
66+ (1 to 50 ).par.foreach(each => roundtripClient(each, address, port))
6967 browserClient()
7068
7169 def server (address : String , port : Int ): Unit = {
@@ -81,8 +79,6 @@ object HttpFileEcho extends App with JsonProtocol {
8179
8280 def routes : Route = logRequestResult(" fileecho" ) {
8381 path(" upload" ) {
84- withRequestTimeout(60 .seconds) {
85-
8682 formFields(Symbol (" payload" )) { payload =>
8783 println(s " Server received request with additional form data: $payload" )
8884
@@ -97,7 +93,6 @@ object HttpFileEcho extends App with JsonProtocol {
9793 complete(Future (FileHandle (uploadedFile.getName, uploadedFile.getAbsolutePath, uploadedFile.length())))
9894 }
9995 }
100- }
10196 } ~
10297 path(" download" ) {
10398 get {
@@ -155,15 +150,15 @@ object HttpFileEcho extends App with JsonProtocol {
155150 def createEntityFrom (file : File ): Future [RequestEntity ] = {
156151 require(file.exists())
157152
158- val compressedFileSource = FileIO .fromPath(file.toPath, chuckSizeBytes).via( Compression .gzip )
153+ val fileSource = FileIO .fromPath(file.toPath, chuckSizeBytes)
159154 val formData = Multipart .FormData (Multipart .FormData .BodyPart (
160155 " binary" ,
161- HttpEntity (MediaTypes .`application/octet-stream`, file.length(), compressedFileSource ),
156+ HttpEntity (MediaTypes .`application/octet-stream`, file.length(), fileSource ),
162157 // Set the Content-Disposition header
163158 // see: https://www.w3.org/Protocols/HTTP/Issues/content-disposition.txt
164159 Map (" filename" -> file.getName)),
165160 // Pass additional (json) payload in a form field
166- Multipart .FormData .BodyPart .Strict (" payload" , " {\" payload\" : \" sent from Scala client\" }" , Map .empty)
161+ Multipart .FormData .BodyPart .Strict (" payload" , s " { \" payload \" : \" sent from Scala client with id: $id \" } " , Map .empty)
167162 )
168163
169164 Marshal (formData).to[RequestEntity ]
@@ -235,7 +230,6 @@ object HttpFileEcho extends App with JsonProtocol {
235230
236231 def saveResponseToFile (response : HttpResponse , localFile : File ) = {
237232 response.entity.dataBytes
238- .via(Compression .gunzip(chuckSizeBytes))
239233 .runWith(FileIO .toPath(Paths .get(localFile.getAbsolutePath)))
240234 }
241235
@@ -247,7 +241,7 @@ object HttpFileEcho extends App with JsonProtocol {
247241 downloaded <- saveResponseToFile(response, localFile)
248242 } yield downloaded
249243
250- val ioresult = Await .result(result, 1 .minute )
244+ val ioresult = Await .result(result, 180 .seconds )
251245 println(s " DownloadClient with id: $id finished downloading: ${ioresult.count} bytes to file: ${localFile.getAbsolutePath}" )
252246 }
253247
0 commit comments