spray icon indicating copy to clipboard operation
spray copied to clipboard

Corrupted response during compression

Open vans239 opened this issue 10 years ago • 0 comments

Encoder produces wrong compressed file in case of big files (multiple chunks)

object GzipTest extends App {
  val file = new File("xxxx") //some big file
  val bytes = IOUtils.toByteArray(new FileInputStream(file))

  class Test extends HttpServiceActor {
    override def receive: Receive = runRoute {
      compressResponseIfRequested() {
        path("a" / IntNumber) { n =>
          complete(HttpEntity(ContentTypes.`application/json`, HttpData(bytes take n)))
        } ~ path("b" / IntNumber) { n =>
          complete(HttpEntity(ContentTypes.`application/json`, HttpData(file, 0, n)))
        }
      }
    }
  }

  val system = ActorSystem()
  //start actor

These commands will produce files with different sizes (first corrupred, second good)

wget -vS --header='Accept-encoding:gzip' localhost:.../b/131073 
wget -vS --header='Accept-encoding:gzip' localhost:.../a/131073 

vans239 avatar Nov 30 '15 20:11 vans239