-
- All Known Implementing Classes:
AbstractRequestContent
,AsyncRequestContent
,ByteBufferRequestContent
,BytesRequestContent
,FormRequestContent
,InputStreamRequestContent
,MultiPartRequestContent
,OutputStreamRequestContent
,PathRequestContent
,StringRequestContent
- Enclosing interface:
- Request
public static interface Request.Content
A reactive model to produce request content, similar to
Flow.Publisher
.Implementations receive the content consumer via
subscribe(Consumer, boolean)
, and return aRequest.Content.Subscription
as the link between producer and consumer.Content producers must notify content to the consumer only if there is demand.
Content consumers can generate demand for content by invoking
Request.Content.Subscription.demand()
.Content production must follow this algorithm:
- the first time content is demanded
- when the content is not available => produce an empty content
- when the content is available:
- when
emitInitialContent == false
=> produce an empty content - when
emitInitialContent == true
=> produce the content
- when
- the second and subsequent times content is demanded
- when the content is not available => do not produce content
- when the content is available => produce the content
- See Also:
subscribe(Consumer, boolean)
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Request.Content.Consumer
A reactive model to consume request content, similar toFlow.Subscriber
.static interface
Request.Content.Subscription
The link between a content producer and a content consumer.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
fail(java.lang.Throwable failure)
Fails this request content, possibly failing and discarding accumulated content that was not demanded.default java.lang.String
getContentType()
default long
getLength()
default boolean
isReproducible()
Whether this content producer can produce exactly the same content more than once.Request.Content.Subscription
subscribe(Request.Content.Consumer consumer, boolean emitInitialContent)
Initializes this content producer with the content consumer, and with the indication of whether initial content, if present, must be emitted upon the initial demand of content (to support delaying the send of the request content in case ofExpect: 100-Continue
whenemitInitialContent
isfalse
).
-
-
-
Method Detail
-
getContentType
default java.lang.String getContentType()
- Returns:
- the content type string such as "application/octet-stream" or "application/json;charset=UTF8", or null if no content type must be set
-
getLength
default long getLength()
- Returns:
- the content length, if known, or -1 if the content length is unknown
-
isReproducible
default boolean isReproducible()
Whether this content producer can produce exactly the same content more than once.
Implementations should return
true
only if the content can be produced more than once, which means thatsubscribe(Consumer, boolean)
may be called again.The
HttpClient
implementation may use this method in particular cases where it detects that it is safe to retry a request that failed.- Returns:
- whether the content can be produced more than once
-
subscribe
Request.Content.Subscription subscribe(Request.Content.Consumer consumer, boolean emitInitialContent)
Initializes this content producer with the content consumer, and with the indication of whether initial content, if present, must be emitted upon the initial demand of content (to support delaying the send of the request content in case of
Expect: 100-Continue
whenemitInitialContent
isfalse
).- Parameters:
consumer
- the content consumer to invoke when there is demand for contentemitInitialContent
- whether to emit initial content, if present- Returns:
- the Subscription that links this producer to the consumer
-
fail
default void fail(java.lang.Throwable failure)
Fails this request content, possibly failing and discarding accumulated content that was not demanded.
The failure may be notified to the consumer at a later time, when the consumer demands for content.
Typical failure: the request being aborted by user code, or idle timeouts.
- Parameters:
failure
- the reason of the failure
-
-