#19983 Add withoutSizeLimit overrides for Scala API.
This commit is contained in:
parent
85aa2197af
commit
dd1495037b
2 changed files with 40 additions and 1 deletions
|
|
@ -126,6 +126,11 @@ sealed trait RequestEntity extends HttpEntity with jm.RequestEntity with Respons
|
|||
*/
|
||||
def withSizeLimit(maxBytes: Long): RequestEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withoutSizeLimit]].
|
||||
*/
|
||||
def withoutSizeLimit: RequestEntity
|
||||
|
||||
def transformDataBytes(transformer: Flow[ByteString, ByteString, Any]): RequestEntity
|
||||
}
|
||||
|
||||
|
|
@ -142,6 +147,11 @@ sealed trait ResponseEntity extends HttpEntity with jm.ResponseEntity {
|
|||
*/
|
||||
def withSizeLimit(maxBytes: Long): ResponseEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withoutSizeLimit]]
|
||||
*/
|
||||
def withoutSizeLimit: ResponseEntity
|
||||
|
||||
def transformDataBytes(transformer: Flow[ByteString, ByteString, Any]): ResponseEntity
|
||||
}
|
||||
/* An entity that can be used for requests, responses, and body parts */
|
||||
|
|
@ -153,6 +163,11 @@ sealed trait UniversalEntity extends jm.UniversalEntity with MessageEntity with
|
|||
*/
|
||||
def withSizeLimit(maxBytes: Long): UniversalEntity
|
||||
|
||||
/**
|
||||
* See [[HttpEntity#withoutSizeLimit]]
|
||||
*/
|
||||
def withoutSizeLimit: UniversalEntity
|
||||
|
||||
def contentLength: Long
|
||||
def contentLengthOption: Option[Long] = Some(contentLength)
|
||||
|
||||
|
|
@ -228,7 +243,7 @@ object HttpEntity {
|
|||
if (contentType == this.contentType) this else copy(contentType = contentType)
|
||||
|
||||
override def withSizeLimit(maxBytes: Long): UniversalEntity =
|
||||
if (data.length <= maxBytes) this
|
||||
if (data.length <= maxBytes || isKnownEmpty) this
|
||||
else HttpEntity.Default(contentType, data.length, limitableByteSource(Source.single(data))) withSizeLimit maxBytes
|
||||
|
||||
override def withoutSizeLimit: UniversalEntity =
|
||||
|
|
|
|||
|
|
@ -149,6 +149,28 @@ class HttpEntitySpec extends FreeSpec with MustMatchers with BeforeAndAfterAll {
|
|||
entity.toString must include(entity.productPrefix)
|
||||
}
|
||||
}
|
||||
"support withoutSizeLimit" - {
|
||||
"Strict" in {
|
||||
HttpEntity.Empty.withoutSizeLimit
|
||||
withReturnType[UniversalEntity](Strict(tpe, abc).withoutSizeLimit)
|
||||
withReturnType[RequestEntity](Strict(tpe, abc).asInstanceOf[RequestEntity].withoutSizeLimit)
|
||||
withReturnType[ResponseEntity](Strict(tpe, abc).asInstanceOf[ResponseEntity].withoutSizeLimit)
|
||||
}
|
||||
"Default" in {
|
||||
withReturnType[Default](Default(tpe, 11, source(abc, de, fgh, ijk)).withoutSizeLimit)
|
||||
withReturnType[RequestEntity](Default(tpe, 11, source(abc, de, fgh, ijk)).asInstanceOf[RequestEntity].withoutSizeLimit)
|
||||
withReturnType[ResponseEntity](Default(tpe, 11, source(abc, de, fgh, ijk)).asInstanceOf[ResponseEntity].withoutSizeLimit)
|
||||
}
|
||||
"CloseDelimited" in {
|
||||
withReturnType[CloseDelimited](CloseDelimited(tpe, source(abc, de, fgh, ijk)).withoutSizeLimit)
|
||||
withReturnType[ResponseEntity](CloseDelimited(tpe, source(abc, de, fgh, ijk)).asInstanceOf[ResponseEntity].withoutSizeLimit)
|
||||
}
|
||||
"Chunked" in {
|
||||
withReturnType[Chunked](Chunked(tpe, source(Chunk(abc), Chunk(fgh), Chunk(ijk), LastChunk)).withoutSizeLimit)
|
||||
withReturnType[RequestEntity](Chunked(tpe, source(Chunk(abc), Chunk(fgh), Chunk(ijk), LastChunk)).asInstanceOf[RequestEntity].withoutSizeLimit)
|
||||
withReturnType[ResponseEntity](Chunked(tpe, source(Chunk(abc), Chunk(fgh), Chunk(ijk), LastChunk)).asInstanceOf[ResponseEntity].withoutSizeLimit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def source[T](elems: T*) = Source(elems.toList)
|
||||
|
|
@ -159,6 +181,8 @@ class HttpEntitySpec extends FreeSpec with MustMatchers with BeforeAndAfterAll {
|
|||
Await.result(future, 250.millis)
|
||||
}
|
||||
|
||||
def withReturnType[T](expr: T) = expr
|
||||
|
||||
def strictifyTo(strict: Strict): Matcher[HttpEntity] =
|
||||
equal(strict).matcher[Strict].compose(x ⇒ Await.result(x.toStrict(250.millis), 250.millis))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue