Package akka.http.javadsl.model
Interface HttpEntity
-
- All Known Subinterfaces:
BodyPartEntity
,BodyPartEntity
,HttpEntity
,HttpEntity.Chunked
,HttpEntity.CloseDelimited
,HttpEntity.Default
,HttpEntity.IndefiniteLength
,HttpEntity.Strict
,HttpEntity.WithoutKnownLength
,RequestEntity
,RequestEntity
,ResponseEntity
,ResponseEntity
,UniversalEntity
,UniversalEntity
- All Known Implementing Classes:
HttpEntity.Chunked
,HttpEntity.CloseDelimited
,HttpEntity.Default
,HttpEntity.IndefiniteLength
,HttpEntity.Strict
@DoNotInherit public interface HttpEntity
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.- See Also:
for javadsl convenience methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
HttpEntity.Chunked
Represents an entity transferred using `Transfer-Encoding: chunked`.static class
HttpEntity.ChunkStreamPart
A part of a stream of incoming data for `Transfer-Encoding: chunked` messages.static interface
HttpEntity.CloseDelimited
Represents an entity without a predetermined content-length.static interface
HttpEntity.Default
The default entity type which has a predetermined length and a stream of data bytes.static interface
HttpEntity.DiscardedEntity
Represents the currently being-drained HTTP Entity which triggers completion of the contained Future once the entity has been drained for the given HttpMessage completely.static interface
HttpEntity.IndefiniteLength
Represents an entity without a predetermined content-length to use in a BodyParts.static interface
HttpEntity.Strict
The entity type which consists of a predefined fixed ByteString of data.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description HttpMessage.DiscardedEntity
discardBytes(akka.actor.ClassicActorSystemProvider system)
Discards the entities data bytes by running thedataBytes
Source contained in this entity.HttpMessage.DiscardedEntity
discardBytes(akka.stream.Materializer materializer)
Discards the entities data bytes by running thedataBytes
Source contained in this entity.java.util.OptionalLong
getContentLengthOption()
Returns Some(contentLength) if the length is defined and none otherwise.ContentType
getContentType()
Returns the content-type of this entityakka.stream.javadsl.Source<akka.util.ByteString,java.lang.Object>
getDataBytes()
Returns a stream of data bytes this entity consists of.boolean
isChunked()
Returns if this entity is a subtype of HttpEntityChunked.boolean
isCloseDelimited()
Returns if this entity is a subtype of HttpEntityCloseDelimited.boolean
isDefault()
Returns if this entity is a subtype of HttpEntityDefault.boolean
isIndefiniteLength()
Returns if this entity is a subtype of HttpEntityIndefiniteLength.boolean
isKnownEmpty()
Returns if this entity is known to be empty.boolean
isStrict()
Returns if this entity is a subtype of HttpEntityStrict.java.util.concurrent.CompletionStage<HttpEntity.Strict>
toStrict(long timeoutMillis, long maxBytes, akka.actor.ClassicActorSystemProvider system)
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.java.util.concurrent.CompletionStage<HttpEntity.Strict>
toStrict(long timeoutMillis, long maxBytes, akka.stream.Materializer materializer)
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.java.util.concurrent.CompletionStage<HttpEntity.Strict>
toStrict(long timeoutMillis, akka.actor.ClassicActorSystemProvider system)
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.java.util.concurrent.CompletionStage<HttpEntity.Strict>
toStrict(long timeoutMillis, akka.stream.Materializer materializer)
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.HttpEntity
withContentType(ContentType contentType)
Returns a copy of this entity with new content typeHttpEntity
withoutSizeLimit()
Lift the size limit from this entity by returning a new entity instance which skips the size verification.HttpEntity
withSizeLimit(long maxBytes)
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.
-
-
-
Method Detail
-
getContentType
ContentType getContentType()
Returns the content-type of this entity
-
withContentType
HttpEntity withContentType(ContentType contentType)
Returns a copy of this entity with new content type./
-
isKnownEmpty
boolean isKnownEmpty()
Returns if this entity is known to be empty. Open-ended entity types like HttpEntityChunked and HttpCloseDelimited will always return false here.
-
isChunked
boolean isChunked()
Returns if this entity is a subtype of HttpEntityChunked.
-
isStrict
boolean isStrict()
Returns if this entity is a subtype of HttpEntityStrict.
-
isDefault
boolean isDefault()
Returns if this entity is a subtype of HttpEntityDefault.
-
isCloseDelimited
boolean isCloseDelimited()
Returns if this entity is a subtype of HttpEntityCloseDelimited.
-
isIndefiniteLength
boolean isIndefiniteLength()
Returns if this entity is a subtype of HttpEntityIndefiniteLength.
-
getContentLengthOption
java.util.OptionalLong getContentLengthOption()
Returns Some(contentLength) if the length is defined and none otherwise.
-
getDataBytes
akka.stream.javadsl.Source<akka.util.ByteString,java.lang.Object> getDataBytes()
Returns a stream of data bytes this entity consists of.
-
withSizeLimit
HttpEntity withSizeLimit(long maxBytes)
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.
-
withoutSizeLimit
HttpEntity withoutSizeLimit()
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.
-
toStrict
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, akka.stream.Materializer materializer)
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.
-
toStrict
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, long maxBytes, akka.stream.Materializer materializer)
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.
-
toStrict
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, akka.actor.ClassicActorSystemProvider system)
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.
-
toStrict
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, long maxBytes, akka.actor.ClassicActorSystemProvider system)
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.
-
discardBytes
HttpMessage.DiscardedEntity discardBytes(akka.stream.Materializer materializer)
Discards the entities data bytes by running thedataBytes
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 thedataBytes
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.
-
discardBytes
HttpMessage.DiscardedEntity discardBytes(akka.actor.ClassicActorSystemProvider system)
Discards the entities data bytes by running thedataBytes
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 thedataBytes
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.
-
-