@@ -10,7 +10,7 @@ import org.apache.pekko.http.scaladsl.server.Route
10
10
import org .apache .pekko .http .scaladsl .server .directives .FileInfo
11
11
import org .apache .pekko .http .scaladsl .unmarshalling .Unmarshal
12
12
import 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 }
14
14
import spray .json .{DefaultJsonProtocol , RootJsonFormat }
15
15
16
16
import java .io .File
@@ -45,9 +45,7 @@ trait JsonProtocol extends DefaultJsonProtocol with SprayJsonSupport {
45
45
* Added:
46
46
* - Retry on upload/download
47
47
* 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
51
49
*
52
50
* To prove that the streaming works:
53
51
* - Replace testfile.jpg with a large file, eg 63MB.pdf
@@ -65,7 +63,7 @@ object HttpFileEcho extends App with JsonProtocol {
65
63
val chuckSizeBytes = 100 * 1024 // to handle large files
66
64
67
65
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))
69
67
browserClient()
70
68
71
69
def server (address : String , port : Int ): Unit = {
@@ -81,8 +79,6 @@ object HttpFileEcho extends App with JsonProtocol {
81
79
82
80
def routes : Route = logRequestResult(" fileecho" ) {
83
81
path(" upload" ) {
84
- withRequestTimeout(60 .seconds) {
85
-
86
82
formFields(Symbol (" payload" )) { payload =>
87
83
println(s " Server received request with additional form data: $payload" )
88
84
@@ -97,7 +93,6 @@ object HttpFileEcho extends App with JsonProtocol {
97
93
complete(Future (FileHandle (uploadedFile.getName, uploadedFile.getAbsolutePath, uploadedFile.length())))
98
94
}
99
95
}
100
- }
101
96
} ~
102
97
path(" download" ) {
103
98
get {
@@ -155,15 +150,15 @@ object HttpFileEcho extends App with JsonProtocol {
155
150
def createEntityFrom (file : File ): Future [RequestEntity ] = {
156
151
require(file.exists())
157
152
158
- val compressedFileSource = FileIO .fromPath(file.toPath, chuckSizeBytes).via( Compression .gzip )
153
+ val fileSource = FileIO .fromPath(file.toPath, chuckSizeBytes)
159
154
val formData = Multipart .FormData (Multipart .FormData .BodyPart (
160
155
" binary" ,
161
- HttpEntity (MediaTypes .`application/octet-stream`, file.length(), compressedFileSource ),
156
+ HttpEntity (MediaTypes .`application/octet-stream`, file.length(), fileSource ),
162
157
// Set the Content-Disposition header
163
158
// see: https://www.w3.org/Protocols/HTTP/Issues/content-disposition.txt
164
159
Map (" filename" -> file.getName)),
165
160
// 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)
167
162
)
168
163
169
164
Marshal (formData).to[RequestEntity ]
@@ -235,7 +230,6 @@ object HttpFileEcho extends App with JsonProtocol {
235
230
236
231
def saveResponseToFile (response : HttpResponse , localFile : File ) = {
237
232
response.entity.dataBytes
238
- .via(Compression .gunzip(chuckSizeBytes))
239
233
.runWith(FileIO .toPath(Paths .get(localFile.getAbsolutePath)))
240
234
}
241
235
@@ -247,7 +241,7 @@ object HttpFileEcho extends App with JsonProtocol {
247
241
downloaded <- saveResponseToFile(response, localFile)
248
242
} yield downloaded
249
243
250
- val ioresult = Await .result(result, 1 .minute )
244
+ val ioresult = Await .result(result, 180 .seconds )
251
245
println(s " DownloadClient with id: $id finished downloading: ${ioresult.count} bytes to file: ${localFile.getAbsolutePath}" )
252
246
}
253
247
0 commit comments