Skip to content

Commit

Permalink
Merge pull request #135 from ing-bank/bug/content-length-size
Browse files Browse the repository at this point in the history
Bug - fakeEntity content length
  • Loading branch information
arempter authored Apr 28, 2020
2 parents c1afefc + d519827 commit 3ce8ecf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ object CacheHelpers {
// https://github.com/akka/akka-http/issues/377
// return a pseudo Default entity that contains the content-length and an Empty data stream
def generateFakeEntity(contentLength: Int): HttpEntity.Default = {
HttpEntity.Default(
ContentType.WithMissingCharset(MediaTypes.`text/plain`),
contentLength,
Source(ByteString() :: Nil)
)
val entityWithSize: Int => HttpEntity.Default = cl =>
HttpEntity.Default(
ContentType.WithMissingCharset(MediaTypes.`text/plain`),
cl,
Source(ByteString() :: Nil)
)

if (contentLength == 0) {
entityWithSize(1)
} else {
entityWithSize(contentLength)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ing.wbaa.rokku.proxy.cache

import com.ing.wbaa.rokku.proxy.handler.parsers.CacheHelpers._
import org.scalatest.diagrams.Diagrams
import org.scalatest.wordspec.AnyWordSpec

class CacheHelpersSpec extends AnyWordSpec with Diagrams {

"Hazelcast Cache helpers" should {
"returns non empty Entity if incorrect CL" in {
assert(generateFakeEntity(0).contentLength == 1)
}
}

}

0 comments on commit 3ce8ecf

Please sign in to comment.