trait HttpEntity extends AnyRef

Represents the entity of an Http message. An entity consists of the content-type of the data and the actual data itself. Some subtypes of HttpEntity also define the content-length of the data.

An HttpEntity can be of several kinds:

  • HttpEntity.Empty: the statically known empty entity
  • HttpEntity.Strict: an entity containing already evaluated ByteString data
  • HttpEntity.Default: the default entity which has a known length and which contains a stream of ByteStrings.
  • HttpEntity.Chunked: represents an entity that is delivered using Transfer-Encoding: chunked
  • HttpEntity.CloseDelimited: an entity which doesn't have a fixed length but which is delimited by closing the connection.
  • HttpEntity.IndefiniteLength: an entity which doesn't have a fixed length which can be used to construct BodyParts with indefinite length

Marker-interfaces denote which subclasses can be used in which context:

  • RequestEntity: an entity type that can be used in an HttpRequest
  • ResponseEntity: an entity type that can be used in an HttpResponse
  • BodyPartEntity: an entity type that can be used in a BodyPart
  • UniversalEntity: an entity type that can be used in every context

Use the static constructors in HttpEntities to construct instances.

Not meant for user extension.

Annotations
@DoNotInherit()
Source
HttpEntity.java
See also

HttpEntities for javadsl convenience methods.

Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. HttpEntity
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def discardBytes(system: ClassicActorSystemProvider): DiscardedEntity

    Discards the entities data bytes by running the dataBytes Source contained in this entity.

    Discards the entities data bytes by running the dataBytes Source contained in this entity.

    Note: It is crucial that entities are either discarded, or consumed by running the underlying akka.stream.javadsl.Source as otherwise the lack of consuming of the data will trigger back-pressure to the underlying TCP connection (as designed), however possibly leading to an idle-timeout that will close the connection, instead of just having ignored the data.

    Warning: It is not allowed to discard and/or consume the dataBytes more than once as the stream is directly attached to the "live" incoming data source from the underlying TCP connection. Allowing it to be consumable twice would require buffering the incoming data, thus defeating the purpose of its streaming nature. If the dataBytes source is materialized a second time, it will fail with an "stream can cannot be materialized more than once" exception.

    When called on Strict entities or sources whose values can be buffered in memory, the above warnings can be ignored. Repeated materialization is not necessary in this case, avoiding the mentioned exceptions due to the data being held in memory.

    In future versions, more automatic ways to warn or resolve these situations may be introduced, see issue #18716.

  2. abstract def discardBytes(materializer: Materializer): DiscardedEntity

    Discards the entities data bytes by running the dataBytes Source contained in this entity.

    Discards the entities data bytes by running the dataBytes Source contained in this entity.

    Note: It is crucial that entities are either discarded, or consumed by running the underlying akka.stream.javadsl.Source as otherwise the lack of consuming of the data will trigger back-pressure to the underlying TCP connection (as designed), however possibly leading to an idle-timeout that will close the connection, instead of just having ignored the data.

    Warning: It is not allowed to discard and/or consume the dataBytes more than once as the stream is directly attached to the "live" incoming data source from the underlying TCP connection. Allowing it to be consumable twice would require buffering the incoming data, thus defeating the purpose of its streaming nature. If the dataBytes source is materialized a second time, it will fail with an "stream can cannot be materialized more than once" exception.

    When called on Strict entities or sources whose values can be buffered in memory, the above warnings can be ignored. Repeated materialization is not necessary in this case, avoiding the mentioned exceptions due to the data being held in memory.

    In future versions, more automatic ways to warn or resolve these situations may be introduced, see issue #18716.

  3. abstract def getContentLengthOption(): OptionalLong

    Returns Some(contentLength) if the length is defined and none otherwise.

  4. abstract def getContentType(): ContentType

    Returns the content-type of this entity

  5. abstract def getDataBytes(): Source[ByteString, AnyRef]

    Returns a stream of data bytes this entity consists of.

  6. abstract def isChunked(): Boolean

    Returns if this entity is a subtype of HttpEntityChunked.

  7. abstract def isCloseDelimited(): Boolean

    Returns if this entity is a subtype of HttpEntityCloseDelimited.

  8. abstract def isDefault(): Boolean

    Returns if this entity is a subtype of HttpEntityDefault.

  9. abstract def isIndefiniteLength(): Boolean

    Returns if this entity is a subtype of HttpEntityIndefiniteLength.

  10. abstract def isKnownEmpty(): Boolean

    Returns if this entity is known to be empty.

    Returns if this entity is known to be empty. Open-ended entity types like HttpEntityChunked and HttpCloseDelimited will always return false here.

  11. abstract def isStrict(): Boolean

    Returns if this entity is a subtype of HttpEntityStrict.

  12. abstract def toStrict(timeoutMillis: Long, maxBytes: Long, system: ClassicActorSystemProvider): CompletionStage[Strict]

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected.

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected. As the duration of receiving the complete entity cannot be predicted, a timeout needs to be specified to guard the process against running and keeping resources infinitely.

    Use getDataBytes and stream processing instead if the expected data is big or is likely to take a long time.

  13. abstract def toStrict(timeoutMillis: Long, system: ClassicActorSystemProvider): CompletionStage[Strict]

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected.

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected. As the duration of receiving the complete entity cannot be predicted, a timeout needs to be specified to guard the process against running and keeping resources infinitely.

    Use getDataBytes and stream processing instead if the expected data is big or is likely to take a long time.

  14. abstract def toStrict(timeoutMillis: Long, maxBytes: Long, materializer: Materializer): CompletionStage[Strict]

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected.

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected. As the duration of receiving the complete entity cannot be predicted, a timeout needs to be specified to guard the process against running and keeping resources infinitely.

    Use getDataBytes and stream processing instead if the expected data is big or is likely to take a long time.

  15. abstract def toStrict(timeoutMillis: Long, materializer: Materializer): CompletionStage[Strict]

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected.

    Returns a CompletionStage of a strict entity that contains the same data as this entity which is only completed when the complete entity has been collected. As the duration of receiving the complete entity cannot be predicted, a timeout needs to be specified to guard the process against running and keeping resources infinitely.

    Use getDataBytes and stream processing instead if the expected data is big or is likely to take a long time.

  16. abstract def withContentType(contentType: ContentType): HttpEntity

    Returns a copy of this entity with new content type./

  17. abstract def withSizeLimit(maxBytes: Long): HttpEntity

    Apply the given size limit to this entity by returning a new entity instance which automatically verifies that the data stream encapsulated by this instance produces at most maxBytes data bytes.

    Apply the given size limit to this entity by returning a new entity instance which automatically verifies that the data stream encapsulated by this instance produces at most maxBytes data bytes. In case this verification fails the respective stream will be terminated with an EntityStreamException either directly at materialization time (if the Content-Length is known) or whenever more data bytes than allowed have been read.

    When called on Strict entities the method will return the entity itself if the length is within the bound, otherwise a Default entity with a single element data stream. This allows for potential refinement of the entity size limit at a later point (before materialization of the data stream).

    By default all message entities produced by the HTTP layer automatically carry the limit that is defined in the application's max-content-length config setting. If the entity is transformed in a way that changes the Content-Length and then another limit is applied then this new limit will be evaluated against the new Content-Length. If the entity is transformed in a way that changes the Content-Length and no new limit is applied then the previous limit will be applied against the previous Content-Length.

  18. abstract def withoutSizeLimit(): HttpEntity

    Lift the size limit from this entity by returning a new entity instance which skips the size verification.

    Lift the size limit from this entity by returning a new entity instance which skips the size verification.

    By default all message entities produced by the HTTP layer automatically carry the limit that is defined in the application's max-content-length config setting. It is recommended to always keep an upper limit on accepted entities to avoid potential attackers flooding you with too large requests/responses, so use this method with caution.

    See withSizeLimit for more details.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from HttpEntity toany2stringadd[HttpEntity] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (HttpEntity, B)
    Implicit
    This member is added by an implicit conversion from HttpEntity toArrowAssoc[HttpEntity] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. def ensuring(cond: (HttpEntity) => Boolean, msg: => Any): HttpEntity
    Implicit
    This member is added by an implicit conversion from HttpEntity toEnsuring[HttpEntity] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  9. def ensuring(cond: (HttpEntity) => Boolean): HttpEntity
    Implicit
    This member is added by an implicit conversion from HttpEntity toEnsuring[HttpEntity] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: Boolean, msg: => Any): HttpEntity
    Implicit
    This member is added by an implicit conversion from HttpEntity toEnsuring[HttpEntity] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: Boolean): HttpEntity
    Implicit
    This member is added by an implicit conversion from HttpEntity toEnsuring[HttpEntity] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  15. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  18. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  19. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  22. def toString(): String
    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from HttpEntity toStringFormat[HttpEntity] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @deprecated @inline()
    Deprecated

    (Since version 2.12.16) Use formatString.format(value) instead of value.formatted(formatString), or use the f"" string interpolator. In Java 15 and later, formatted resolves to the new method in String which has reversed parameters.

  2. def [B](y: B): (HttpEntity, B)
    Implicit
    This member is added by an implicit conversion from HttpEntity toArrowAssoc[HttpEntity] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromHttpEntity to any2stringadd[HttpEntity]

Inherited by implicit conversion StringFormat fromHttpEntity to StringFormat[HttpEntity]

Inherited by implicit conversion Ensuring fromHttpEntity to Ensuring[HttpEntity]

Inherited by implicit conversion ArrowAssoc fromHttpEntity to ArrowAssoc[HttpEntity]

Ungrouped