Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Release version 0.7.1 #67

Merged
merged 2 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
In your project/Build.scala:
```scala
libraryDependencies ++= Seq(
"com.mohiva" %% "play-html-compressor" % "0.7.0"
"com.mohiva" %% "play-html-compressor" % "0.7.1"
)
```

### History

* For Play Framework 2.6 use version 0.7.0
* For Play Framework 2.6 use version 0.7.1
* For Play Framework 2.5 use version 0.6.3
* For Play Framework 2.4 use version 0.5.0
* For Play Framework 2.3 use version 0.3.1
Expand Down
16 changes: 5 additions & 11 deletions app/com/mohiva/play/compressor/CompressorFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,22 @@ abstract class CompressorFilter[C <: Compressor] extends Filter {
* @return The compressed result.
*/
private def compressResult(result: Result): Future[Result] = {

def compress(data: ByteString) = compressor.compress(data.decodeString(charset).trim).getBytes(charset)

if (isCompressible(result)) {
result.body match {
case body0: HttpEntity.Strict =>
case body: HttpEntity.Strict =>
Future.successful(
result.copy(
body = body0.copy(
data = ByteString(compress(body0.data))
)
)
result.copy(body = body.copy(ByteString(compress(body.data))))
)
case body0: HttpEntity.Streamed =>
case body: HttpEntity.Streamed =>
for {
bytes <- body0.data.toMat(Sink.fold(ByteString())(_ ++ _))(Keep.right).run()
bytes <- body.data.toMat(Sink.fold(ByteString())(_ ++ _))(Keep.right).run()
} yield {
val compressed = compress(bytes)
val length = compressed.length
result.copy(
body = body0.copy(
body = body.copy(
data = Source.single(ByteString(compressed)),
contentLength = Some(length.toLong)
)
Expand All @@ -116,5 +111,4 @@ abstract class CompressorFilter[C <: Compressor] extends Filter {
Future.successful(result)
}
}

}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/release

resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.1")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.6.0")

Expand Down