requests-scala
requests-scala copied to clipboard
Compression broken
POSTing compressed data fails. For a small file, examining the bytes actually received reveals them to be "31,139,8,0,0,0,0,0,0,0,-1". The 31,139 means gzip, the -1 is end of file, the rest I suspect means "I forgot to close/finish the GZIPOutputStream. Looking for the code in requests/Requester.scala there is a section that I suspect should be changed to something like the following. Admittedly I haven't gotten my Ammonite script to use it, yet, but I'd be surprised if isn't the issue. I notice there are tests for the compression modes but they clearly proved insufficient.
if (!chunkedUpload) {
val bytes = new ByteArrayOutputStream()
val os = compress.wrap(connection.getOutputStream)
data.write(os)
os.close()
val byteArray = bytes.toByteArray
connection.setFixedLengthStreamingMode(byteArray.length)
if (byteArray.nonEmpty) connection.getOutputStream.write(byteArray)
} else {
connection.setChunkedStreamingMode(0)
val os = compress.wrap(connection.getOutputStream)
data.write(os)
os.close()
}
}