public interface HttpEntity extends HttpEntity
Modifier and Type | Interface and Description |
---|---|
static class |
HttpEntity.Chunk
An intermediate entity chunk guaranteed to carry non-empty data.
|
static class |
HttpEntity.Chunk$ |
static class |
HttpEntity.Chunked
The model for the entity of a chunked HTTP message (with
Transfer-Encoding: chunked ). |
static class |
HttpEntity.Chunked$ |
static class |
HttpEntity.ChunkStreamPart
An element of the HttpEntity data stream.
|
static class |
HttpEntity.ChunkStreamPart$ |
static class |
HttpEntity.CloseDelimited
The model for the entity of an HTTP response that is terminated by the server closing the connection.
|
static class |
HttpEntity.CloseDelimited$ |
static class |
HttpEntity.Default
The model for the entity of a "regular" unchunked HTTP message with a known non-zero length.
|
static class |
HttpEntity.Default$ |
static class |
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 class |
HttpEntity.HttpEntityScalaDSLSugar
Adds Scala DSL idiomatic methods to
HttpEntity , e.g. versions of methods with an implicit Materializer . |
static class |
HttpEntity.HttpEntityScalaDSLSugar$ |
static class |
HttpEntity.IndefiniteLength
The model for the entity of a BodyPart with an indefinite length.
|
static class |
HttpEntity.IndefiniteLength$ |
static class |
HttpEntity.LastChunk
The final chunk of a chunk stream.
|
static class |
HttpEntity.LastChunk$ |
static class |
HttpEntity.Strict
The model for the entity of a "regular" unchunked HTTP message with known, fixed data.
|
static class |
HttpEntity.Strict$ |
static interface |
HttpEntity.WithoutKnownLength
Supertype of CloseDelimited and IndefiniteLength.
|
Modifier and Type | Method and Description |
---|---|
<T,U> java.util.concurrent.CompletionStage<U> |
completionStageCovariant(java.util.concurrent.CompletionStage<T> in) |
scala.Option<java.lang.Object> |
contentLengthOption()
Some(content length) if a length is defined for this entity, None otherwise.
|
ContentType |
contentType()
The
ContentType associated with this entity. |
org.apache.pekko.stream.scaladsl.Source<org.apache.pekko.util.ByteString,java.lang.Object> |
dataBytes()
A stream of the data of this entity.
|
HttpMessage.DiscardedEntity |
discardBytes(org.apache.pekko.actor.ClassicActorSystemProvider system)
Java API
|
HttpMessage.DiscardedEntity |
discardBytes(org.apache.pekko.stream.Materializer mat)
Discards the entities data bytes by running the
dataBytes Source contained in this entity . |
java.util.OptionalLong |
getContentLengthOption()
Java API
|
ContentType |
getContentType()
Java API
|
org.apache.pekko.stream.javadsl.Source<org.apache.pekko.util.ByteString,java.lang.Object> |
getDataBytes()
Java API
|
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()
Determines whether this entity is known to be empty.
|
boolean |
isStrict()
Returns if this entity is a subtype of HttpEntityStrict.
|
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.
|
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.
|
java.util.concurrent.CompletionStage<HttpEntity.Strict> |
toStrict(long timeoutMillis,
org.apache.pekko.actor.ClassicActorSystemProvider system)
Java API
|
java.util.concurrent.CompletionStage<HttpEntity.Strict> |
toStrict(long timeoutMillis,
long maxBytes,
org.apache.pekko.actor.ClassicActorSystemProvider system)
Java API
|
java.util.concurrent.CompletionStage<HttpEntity.Strict> |
toStrict(long timeoutMillis,
long maxBytes,
org.apache.pekko.stream.Materializer materializer)
Java API
|
java.util.concurrent.CompletionStage<HttpEntity.Strict> |
toStrict(long timeoutMillis,
org.apache.pekko.stream.Materializer materializer)
Java API
|
HttpEntity |
transformDataBytes(org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString,org.apache.pekko.util.ByteString,java.lang.Object> transformer)
Returns a copy of the given entity with the ByteString chunks of this entity transformed by the given transformer.
|
UniversalEntity |
transformDataBytes(long newContentLength,
org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString,org.apache.pekko.util.ByteString,java.lang.Object> transformer)
Transforms this' entities data bytes with a transformer that will produce exactly the number of bytes given as
newContentLength . |
HttpEntity |
withContentType(ContentType contentType)
Creates a copy of this HttpEntity with the
contentType overridden with the given one. |
HttpEntity |
withContentType(ContentType contentType)
Java API
|
HttpEntity |
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. |
<T,U> java.util.concurrent.CompletionStage<U> completionStageCovariant(java.util.concurrent.CompletionStage<T> in)
boolean isKnownEmpty()
isKnownEmpty
in interface HttpEntity
ContentType contentType()
ContentType
associated with this entity.scala.Option<java.lang.Object> contentLengthOption()
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.
org.apache.pekko.stream.scaladsl.Source<org.apache.pekko.util.ByteString,java.lang.Object> dataBytes()
scala.concurrent.Future<HttpEntity.Strict> toStrict(scala.concurrent.duration.FiniteDuration timeout, org.apache.pekko.stream.Materializer fm)
pekko.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 the toStrict
method and pass in an explicit
maximum number of bytes.timeout
- (undocumented)fm
- (undocumented)scala.concurrent.Future<HttpEntity.Strict> toStrict(scala.concurrent.duration.FiniteDuration timeout, long maxBytes, org.apache.pekko.stream.Materializer fm)
timeout
- (undocumented)maxBytes
- (undocumented)fm
- (undocumented)HttpMessage.DiscardedEntity discardBytes(org.apache.pekko.stream.Materializer mat)
dataBytes
Source contained in this entity
.
Note: It is crucial that entities are either discarded, or consumed by running the underlying pekko.stream.scaladsl.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 entity.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.
discardBytes
in interface HttpEntity
mat
- (undocumented)HttpMessage.DiscardedEntity discardBytes(org.apache.pekko.actor.ClassicActorSystemProvider system)
discardBytes
in interface HttpEntity
HttpEntity transformDataBytes(org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString,org.apache.pekko.util.ByteString,java.lang.Object> transformer)
Chunked
entity, the chunks will be transformed one by one keeping the chunk metadata (but may introduce an
extra chunk before the LastChunk
if transformer.onTermination
returns additional data).
This method may only throw an exception if the transformer
function throws an exception while creating the transformer.
Any other errors are reported through the new entity data stream.
transformer
- (undocumented)UniversalEntity transformDataBytes(long newContentLength, org.apache.pekko.stream.scaladsl.Flow<org.apache.pekko.util.ByteString,org.apache.pekko.util.ByteString,java.lang.Object> transformer)
newContentLength
.newContentLength
- (undocumented)transformer
- (undocumented)HttpEntity withContentType(ContentType contentType)
contentType
overridden with the given one.contentType
- (undocumented)HttpEntity withSizeLimit(long maxBytes)
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.
withSizeLimit
in interface HttpEntity
maxBytes
- (undocumented)HttpEntity withoutSizeLimit()
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.
withoutSizeLimit
in interface HttpEntity
ContentType getContentType()
getContentType
in interface HttpEntity
org.apache.pekko.stream.javadsl.Source<org.apache.pekko.util.ByteString,java.lang.Object> getDataBytes()
getDataBytes
in interface HttpEntity
java.util.OptionalLong getContentLengthOption()
getContentLengthOption
in interface HttpEntity
boolean isCloseDelimited()
HttpEntity
isCloseDelimited
in interface HttpEntity
boolean isIndefiniteLength()
HttpEntity
isIndefiniteLength
in interface HttpEntity
boolean isStrict()
HttpEntity
isStrict
in interface HttpEntity
boolean isDefault()
HttpEntity
isDefault
in interface HttpEntity
boolean isChunked()
HttpEntity
isChunked
in interface HttpEntity
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, org.apache.pekko.stream.Materializer materializer)
toStrict
in interface HttpEntity
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, long maxBytes, org.apache.pekko.stream.Materializer materializer)
toStrict
in interface HttpEntity
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, org.apache.pekko.actor.ClassicActorSystemProvider system)
toStrict
in interface HttpEntity
java.util.concurrent.CompletionStage<HttpEntity.Strict> toStrict(long timeoutMillis, long maxBytes, org.apache.pekko.actor.ClassicActorSystemProvider system)
toStrict
in interface HttpEntity
HttpEntity withContentType(ContentType contentType)
withContentType
in interface HttpEntity