sealed abstract class Chunk extends AnyRef
Represents a piece of an HTTP stream, commonly referred to as a chunk.
HTTP semantics treat trailing headers as the end of stream signal hence no writes (neither
trailers nor data) are allowed after them, only close
(EOS) is valid. This is typically
enforced by an HTTP dispatcher in both clients and servers.
Similarly, when consumed via com.twitter.io.Reader, trailers are always followed by None
,
readers's EOS. Users MUST read until the end of stream to ensure resource hygiene.
The following example demonstrates one way of doing so: wiring in one extra read before returning from a read-loop:
def accumulate(r: Reader[Chunk]): Future[(Buf, Option[HeaderMap])] = { def loop(acc: Buf, trailers: Option[HeaderMap]): Future[(Buf, Option[HeaderMap])] = r.read().flatMap { case Some(chunk) => if (chunk.isLast && !chunk.trailers.isEmpty) loop(acc.concat(chunk.content), Some(chunk.trailers)) else loop(acc.concat(chunk.content), None) case None => Future.value(acc -> trailers) } loop(Buf.Empty, None) }
The HTTP dispatcher guarantees that Chunk.Last
will be issued in the inbound stream
no matter if its trailers
or content
present.
Note: when consuming interleaved HTTP streams (i.e., via Reader.flatMap
) it's expected to
observe multiple trailers before reaching the EOS. These inter-stream trailers space out
individual HTTP streams from child readers.
- Alphabetic
- By Inheritance
- Chunk
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def content: Buf
The payload of this chunk.
The payload of this chunk. Can be empty if this is a last chunk.
- abstract def isLast: Boolean
Whether this chunk is last in the stream.
- abstract def trailers: HeaderMap
The trailing headers of this chunk.
The trailing headers of this chunk. Can throw IllegalArgumentException if this is not the last chunk.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()