Interface HttpEntity
- All Superinterfaces:
HttpEntity
- All Known Subinterfaces:
BodyPartEntity,HttpEntity.WithoutKnownLength,RequestEntity,ResponseEntity,UniversalEntity
- All Known Implementing Classes:
HttpEntity.Chunked,HttpEntity.CloseDelimited,HttpEntity.Default,HttpEntity.IndefiniteLength,HttpEntity.Strict
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classAn intermediate entity chunk guaranteed to carry non-empty data.static classstatic final classThe model for the entity of a chunked HTTP message (withTransfer-Encoding: chunked).static classstatic classAn element of the HttpEntity data stream.static classstatic final classThe model for the entity of an HTTP response that is terminated by the server closing the connection.static classstatic final classThe model for the entity of a "regular" unchunked HTTP message with a known non-zero length.static classstatic final classRepresents 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 final classAdds Scala DSL idiomatic methods toHttpEntity, e.g. versions of methods with an implicitMaterializer.static classstatic final classThe model for the entity of a BodyPart with an indefinite length.static classstatic classThe final chunk of a chunk stream.static classstatic final classThe model for the entity of a "regular" unchunked HTTP message with known, fixed data.static classstatic interfaceSupertype of CloseDelimited and IndefiniteLength. -
Method Summary
Modifier and TypeMethodDescription<T,U> CompletionStage<U> scala.Option<Object>Some(content length) if a length is defined for this entity, None otherwise.TheContentTypeassociated with this entity.org.apache.pekko.stream.scaladsl.Source<org.apache.pekko.util.ByteString,Object> A stream of the data of this entity.discardBytes(org.apache.pekko.actor.ClassicActorSystemProvider system) Java APIdiscardBytes(org.apache.pekko.stream.Materializer mat) Discards the entities data bytes by running thedataBytesSource contained in thisentity.Java APIJava APIorg.apache.pekko.stream.javadsl.Source<org.apache.pekko.util.ByteString,Object> Java APIbooleanReturns if this entity is a subtype of HttpEntityChunked.booleanReturns if this entity is a subtype of HttpEntityCloseDelimited.booleanReturns if this entity is a subtype of HttpEntityDefault.booleanReturns if this entity is a subtype of HttpEntityIndefiniteLength.booleanDetermines whether this entity is known to be empty.booleanisStrict()Returns if this entity is a subtype of HttpEntityStrict.toStrict(long timeoutMillis, long maxBytes, org.apache.pekko.actor.ClassicActorSystemProvider system) Java APItoStrict(long timeoutMillis, long maxBytes, org.apache.pekko.stream.Materializer materializer) Java APItoStrict(long timeoutMillis, org.apache.pekko.actor.ClassicActorSystemProvider system) Java APItoStrict(long timeoutMillis, org.apache.pekko.stream.Materializer materializer) Java APIscala.concurrent.Future<HttpEntity.Strict>toStrict(scala.concurrent.duration.FiniteDuration timeout, long maxBytes, org.apache.pekko.stream.Materializer fm) Collects all possible parts and returns a potentially future Strict entity for easier processing.scala.concurrent.Future<HttpEntity.Strict>toStrict(scala.concurrent.duration.FiniteDuration timeout, org.apache.pekko.stream.Materializer fm) Collects all possible parts and returns a potentially future Strict entity for easier processing.transformDataBytes(long newContentLength, org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString, org.apache.pekko.util.ByteString, Object> transformer) Transforms this' entities data bytes with a transformer that will produce exactly the number of bytes given asnewContentLength.transformDataBytes(org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString, org.apache.pekko.util.ByteString, Object> transformer) Returns a copy of the given entity with the ByteString chunks of this entity transformed by the given transformer.withContentType(ContentType contentType) Java APIwithContentType(ContentType contentType) Creates a copy of this HttpEntity with thecontentTypeoverridden with the given one.Lift the size limit from this entity by returning a new entity instance which skips the size verification.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 mostmaxBytesdata bytes.
-
Method Details
-
completionStageCovariant
-
isKnownEmpty
boolean isKnownEmpty()Determines whether this entity is known to be empty.- Specified by:
isKnownEmptyin interfaceHttpEntity- Returns:
- (undocumented)
-
contentType
ContentType contentType()TheContentTypeassociated with this entity.- Returns:
- (undocumented)
-
contentLengthOption
scala.Option<Object> contentLengthOption()Some(content length) if a length is defined for this entity, None otherwise. A length is only defined for Strict and Default entity types.In many cases it's dangerous to rely on the (non-)existence of a content-length. HTTP intermediaries like (transparent) proxies are allowed to change the transfer-encoding which can result in the entity being delivered as another type as expected.
- Returns:
- (undocumented)
-
dataBytes
org.apache.pekko.stream.scaladsl.Source<org.apache.pekko.util.ByteString,Object> dataBytes()A stream of the data of this entity.- Returns:
- (undocumented)
-
toStrict
scala.concurrent.Future<HttpEntity.Strict> toStrict(scala.concurrent.duration.FiniteDuration timeout, org.apache.pekko.stream.Materializer fm) Collects all possible parts and returns a potentially future Strict entity for easier processing. The Future is failed with an TimeoutException if the stream isn't completed after the given timeout, or with a EntityStreamException when the end of the entity is not reached within the maximum number of bytes as configured inpekko.http.parsing.max-to-strict-bytes. Not that this method does not support different defaults for client- and server use: if you want that, use thetoStrictmethod and pass in an explicit maximum number of bytes.- Parameters:
timeout- (undocumented)fm- (undocumented)- Returns:
- (undocumented)
-
toStrict
scala.concurrent.Future<HttpEntity.Strict> toStrict(scala.concurrent.duration.FiniteDuration timeout, long maxBytes, org.apache.pekko.stream.Materializer fm) Collects all possible parts and returns a potentially future Strict entity for easier processing. The Future is failed with an TimeoutException if the stream isn't completed after the given timeout, or with a EntityStreamException when the end of the entity is not reached within the maximum number of bytes.- Parameters:
timeout- (undocumented)maxBytes- (undocumented)fm- (undocumented)- Returns:
- (undocumented)
-
discardBytes
Discards the entities data bytes by running thedataBytesSource contained in thisentity.Note: It is crucial that entities are either discarded, or consumed by running the underlying
pekko.stream.scaladsl.Sourceas 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
entity.dataBytesmore 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
Strictentities 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.
- Specified by:
discardBytesin interfaceHttpEntity- Parameters:
mat- (undocumented)- Returns:
- (undocumented)
-
discardBytes
Java API- Specified by:
discardBytesin interfaceHttpEntity
-
transformDataBytes
HttpEntity transformDataBytes(org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString, org.apache.pekko.util.ByteString, Object> transformer) Returns a copy of the given entity with the ByteString chunks of this entity transformed by the given transformer. For aChunkedentity, the chunks will be transformed one by one keeping the chunk metadata (but may introduce an extra chunk before theLastChunkiftransformer.onTerminationreturns additional data).This method may only throw an exception if the
transformerfunction throws an exception while creating the transformer. Any other errors are reported through the new entity data stream.- Parameters:
transformer- (undocumented)- Returns:
- (undocumented)
-
transformDataBytes
UniversalEntity transformDataBytes(long newContentLength, org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString, org.apache.pekko.util.ByteString, Object> transformer) Transforms this' entities data bytes with a transformer that will produce exactly the number of bytes given asnewContentLength.- Parameters:
newContentLength- (undocumented)transformer- (undocumented)- Returns:
- (undocumented)
-
withContentType
Creates a copy of this HttpEntity with thecontentTypeoverridden with the given one.- Parameters:
contentType- (undocumented)- Returns:
- (undocumented)
-
withSizeLimit
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 mostmaxBytesdata bytes. In case this verification fails the respective stream will be terminated with anEntityStreamExceptioneither directly at materialization time (if the Content-Length is known) or whenever more data bytes than allowed have been read.When called on
Strictentities the method will return the entity itself if the length is within the bound, otherwise aDefaultentity 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-lengthconfig 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.- Specified by:
withSizeLimitin interfaceHttpEntity- Parameters:
maxBytes- (undocumented)- Returns:
- (undocumented)
-
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-lengthconfig 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(long)for more details.- Specified by:
withoutSizeLimitin interfaceHttpEntity- Returns:
- (undocumented)
-
getContentType
ContentType getContentType()Java API- Specified by:
getContentTypein interfaceHttpEntity
-
getDataBytes
org.apache.pekko.stream.javadsl.Source<org.apache.pekko.util.ByteString,Object> getDataBytes()Java API- Specified by:
getDataBytesin interfaceHttpEntity
-
getContentLengthOption
OptionalLong getContentLengthOption()Java API- Specified by:
getContentLengthOptionin interfaceHttpEntity
-
isCloseDelimited
boolean isCloseDelimited()Description copied from interface:HttpEntityReturns if this entity is a subtype of HttpEntityCloseDelimited.- Specified by:
isCloseDelimitedin interfaceHttpEntity
-
isIndefiniteLength
boolean isIndefiniteLength()Description copied from interface:HttpEntityReturns if this entity is a subtype of HttpEntityIndefiniteLength.- Specified by:
isIndefiniteLengthin interfaceHttpEntity
-
isStrict
boolean isStrict()Description copied from interface:HttpEntityReturns if this entity is a subtype of HttpEntityStrict.- Specified by:
isStrictin interfaceHttpEntity
-
isDefault
boolean isDefault()Description copied from interface:HttpEntityReturns if this entity is a subtype of HttpEntityDefault.- Specified by:
isDefaultin interfaceHttpEntity
-
isChunked
boolean isChunked()Description copied from interface:HttpEntityReturns if this entity is a subtype of HttpEntityChunked.- Specified by:
isChunkedin interfaceHttpEntity
-
toStrict
CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, org.apache.pekko.stream.Materializer materializer) Java API- Specified by:
toStrictin interfaceHttpEntity
-
toStrict
CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, long maxBytes, org.apache.pekko.stream.Materializer materializer) Java API- Specified by:
toStrictin interfaceHttpEntity
-
toStrict
CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, org.apache.pekko.actor.ClassicActorSystemProvider system) Java API- Specified by:
toStrictin interfaceHttpEntity
-
toStrict
CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, long maxBytes, org.apache.pekko.actor.ClassicActorSystemProvider system) Java API- Specified by:
toStrictin interfaceHttpEntity
-
withContentType
Java API- Specified by:
withContentTypein interfaceHttpEntity
-