Package play.http

Class HttpEntity

java.lang.Object
play.http.HttpEntity
Direct Known Subclasses:
HttpEntity.Chunked, HttpEntity.Streamed, HttpEntity.Strict

public abstract class HttpEntity extends Object
An HTTP entity
  • Field Details

    • NO_ENTITY

      public static final HttpEntity NO_ENTITY
      No entity.
  • Method Details

    • contentType

      public abstract Optional<String> contentType()
      Returns:
      The content type, if defined
    • isKnownEmpty

      public abstract boolean isKnownEmpty()
      Returns:
      Whether the entity is known to be empty or not.
    • contentLength

      public abstract Optional<Long> contentLength()
      Returns:
      The content length, if known
    • dataStream

      public abstract Source<ByteString,?> dataStream()
      Returns:
      The stream of data.
    • as

      public abstract HttpEntity as(String contentType)
      Parameters:
      contentType - the content type to use, i.e. "text/html".
      Returns:
      Return the entity as the given content type.
    • consumeData

      public CompletionStage<ByteString> consumeData(Materializer mat)
      Consumes the data.

      This method should be used carefully, since if the source represents an ephemeral stream, then the entity may not be usable after this method is invoked.

      Parameters:
      mat - the application's materializer.
      Returns:
      a CompletionStage holding the data
    • asScala

      public abstract play.api.http.HttpEntity asScala()
    • fromContent

      public static final HttpEntity fromContent(play.twirl.api.Content content, String charset)
      Create an entity from the given content.
      Parameters:
      content - The content.
      charset - The charset.
      Returns:
      the HTTP entity.
    • fromString

      public static final HttpEntity fromString(String content, String charset)
      Create an entity from the given String.
      Parameters:
      content - The content.
      charset - The charset.
      Returns:
      the HTTP entity.
    • chunked

      public static final HttpEntity chunked(Source<ByteString,?> data, Optional<String> contentType)
      Convert the given source of ByteStrings to a chunked entity.
      Parameters:
      data - The source.
      contentType - The optional content type.
      Returns:
      The ByteStrings.