Packages

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.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Chunk
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def content: Buf

    The payload of this chunk.

    The payload of this chunk. Can be empty if this is a last chunk.

  2. abstract def isLast: Boolean

    Whether this chunk is last in the stream.

  3. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped