Interface StreamingHttpResponse
-
- All Superinterfaces:
HttpMetaData
,HttpResponseMetaData
public interface StreamingHttpResponse extends HttpResponseMetaData
The equivalent ofHttpResponse
but provides the payload as aPublisher
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default StreamingHttpResponse
addCookie(HttpCookiePair cookie)
Adds a cookie.default StreamingHttpResponse
addCookie(java.lang.CharSequence name, java.lang.CharSequence value)
default StreamingHttpResponse
addHeader(java.lang.CharSequence name, java.lang.CharSequence value)
Adds a new header with the specifiedname
andvalue
.default StreamingHttpResponse
addHeaders(HttpHeaders headers)
Adds all header names and values ofheaders
object.default StreamingHttpResponse
addSetCookie(HttpSetCookie cookie)
Adds a set-cookie.default StreamingHttpResponse
addSetCookie(java.lang.CharSequence name, java.lang.CharSequence value)
StreamingHttpResponse
encoding(ContentCodec encoding)
TheContentCodec
used to encode the payload of a request or a response.Publisher<java.lang.Object>
messageBody()
Get the message-body which contains the payload body concatenated with the trailer (if present).Publisher<Buffer>
payloadBody()
StreamingHttpResponse
payloadBody(Publisher<Buffer> payloadBody)
Returns aStreamingHttpResponse
with its underlying payload set topayloadBody
.<T> StreamingHttpResponse
payloadBody(Publisher<T> payloadBody, HttpSerializer<T> serializer)
Returns aStreamingHttpResponse
with its underlying payload set to the result of serialization.default <T> Publisher<T>
payloadBody(HttpDeserializer<T> deserializer)
Gets and deserializes the payload body.default StreamingHttpResponse
setHeader(java.lang.CharSequence name, java.lang.CharSequence value)
Sets a header with the specifiedname
andvalue
.default StreamingHttpResponse
setHeaders(HttpHeaders headers)
Clears the current header entries and copies all header entries of the specifiedheaders
object.BlockingStreamingHttpResponse
toBlockingStreamingResponse()
Translates thisStreamingHttpResponse
to aBlockingStreamingHttpResponse
.Single<HttpResponse>
toResponse()
Translates thisStreamingHttpResponse
to aHttpResponse
.<T> StreamingHttpResponse
transform(TrailersTransformer<T,Buffer> trailersTransformer)
Returns aStreamingHttpResponse
with its underlying payload transformed toBuffer
s, with access to the trailers.StreamingHttpResponse
transformMessageBody(java.util.function.UnaryOperator<Publisher<?>> transformer)
Transform the message-body which contains the payload body concatenated with the trailer (if present).<T> StreamingHttpResponse
transformPayloadBody(java.util.function.Function<Publisher<Buffer>,Publisher<T>> transformer, HttpSerializer<T> serializer)
Returns aStreamingHttpResponse
with its underlying payload transformed to the result of serialization.default <T,R>
StreamingHttpResponsetransformPayloadBody(java.util.function.Function<Publisher<T>,Publisher<R>> transformer, HttpDeserializer<T> deserializer, HttpSerializer<R> serializer)
Returns aStreamingHttpResponse
with its underlying payload transformed to the result of serialization.StreamingHttpResponse
transformPayloadBody(java.util.function.UnaryOperator<Publisher<Buffer>> transformer)
Returns aStreamingHttpResponse
with its underlying payload transformed toBuffer
s.StreamingHttpResponse
version(HttpProtocolVersion version)
Set the protocol version of thisHttpMetaData
.-
Methods inherited from interface io.servicetalk.http.api.HttpMetaData
encoding, headers, toString, toString, version
-
Methods inherited from interface io.servicetalk.http.api.HttpResponseMetaData
status, status
-
-
-
-
Method Detail
-
payloadBody
default <T> Publisher<T> payloadBody(HttpDeserializer<T> deserializer)
Gets and deserializes the payload body.- Type Parameters:
T
- The resulting type of the deserialization operation.- Parameters:
deserializer
- The function that deserializes the underlyingPublisher
.- Returns:
- The results of the deserialization operation.
-
messageBody
Publisher<java.lang.Object> messageBody()
Get the message-body which contains the payload body concatenated with the trailer (if present).- Returns:
- a
Publisher
that represents the message-body which contains the payload body concatenated with the trailer (if present).
-
payloadBody
StreamingHttpResponse payloadBody(Publisher<Buffer> payloadBody)
Returns aStreamingHttpResponse
with its underlying payload set topayloadBody
.A best effort will be made to apply back pressure to the existing
Publisher
payload body. If this default policy is not sufficient you can usetransformPayloadBody(UnaryOperator)
for more fine grain control.This method reserves the right to delay completion/consumption of
payloadBody
. This may occur due to the combination with the existingPublisher
payload body.- Parameters:
payloadBody
- The new payload body.- Returns:
this
-
payloadBody
<T> StreamingHttpResponse payloadBody(Publisher<T> payloadBody, HttpSerializer<T> serializer)
Returns aStreamingHttpResponse
with its underlying payload set to the result of serialization.A best effort will be made to apply back pressure to the existing
Publisher
payload body. If this default policy is not sufficient you can usetransformPayloadBody(Function, HttpSerializer)
for more fine grain control.This method reserves the right to delay completion/consumption of
payloadBody
. This may occur due to the combination with the existingPublisher
payload body.- Type Parameters:
T
- The type of objects to serialize.- Parameters:
payloadBody
- The new payload body, prior to serialization.serializer
- Used to serialize the payload body.- Returns:
this
-
transformPayloadBody
<T> StreamingHttpResponse transformPayloadBody(java.util.function.Function<Publisher<Buffer>,Publisher<T>> transformer, HttpSerializer<T> serializer)
Returns aStreamingHttpResponse
with its underlying payload transformed to the result of serialization.- Type Parameters:
T
- The type of objects to serialize.- Parameters:
transformer
- AFunction
which take as a parameter the existing payload bodyPublisher
and returns the new payload bodyPublisher
prior to serialization. It is assumed the existing payload bodyPublisher
will be transformed/consumed or else no more responses may be processed.serializer
- Used to serialize the payload body.- Returns:
this
-
transformPayloadBody
default <T,R> StreamingHttpResponse transformPayloadBody(java.util.function.Function<Publisher<T>,Publisher<R>> transformer, HttpDeserializer<T> deserializer, HttpSerializer<R> serializer)
Returns aStreamingHttpResponse
with its underlying payload transformed to the result of serialization.- Type Parameters:
T
- The type of objects to deserialize.R
- The type of objects to serialize.- Parameters:
transformer
- AFunction
which take as a parameter the existing payload bodyPublisher
and returns the new payload bodyPublisher
prior to serialization. It is assumed the existing payload bodyPublisher
will be transformed/consumed or else no more requests may be processed.deserializer
- Used to deserialize the existing payload body.serializer
- Used to serialize the payload body.- Returns:
this
-
transformPayloadBody
StreamingHttpResponse transformPayloadBody(java.util.function.UnaryOperator<Publisher<Buffer>> transformer)
Returns aStreamingHttpResponse
with its underlying payload transformed toBuffer
s.
-
transformMessageBody
StreamingHttpResponse transformMessageBody(java.util.function.UnaryOperator<Publisher<?>> transformer)
Transform the message-body which contains the payload body concatenated with the trailer (if present).The transformation is not expected to change the presence of trailers in the message body. For example behavior is undefined if a
HttpHeaders
object is inserted to or removed from to the returnedPublisher
. To add or clear trailers usetransform(TrailersTransformer)
.- Parameters:
transformer
- Responsible for transforming the message-body.- Returns:
this
.
-
transform
<T> StreamingHttpResponse transform(TrailersTransformer<T,Buffer> trailersTransformer)
Returns aStreamingHttpResponse
with its underlying payload transformed toBuffer
s, with access to the trailers.- Type Parameters:
T
- The type of state used during the transformation.- Parameters:
trailersTransformer
-TrailersTransformer
to use for this transform.- Returns:
this
-
toResponse
Single<HttpResponse> toResponse()
Translates thisStreamingHttpResponse
to aHttpResponse
.- Returns:
- a
Single
that completes with aHttpResponse
representation of thisStreamingHttpResponse
.
-
toBlockingStreamingResponse
BlockingStreamingHttpResponse toBlockingStreamingResponse()
Translates thisStreamingHttpResponse
to aBlockingStreamingHttpResponse
.- Returns:
- a
BlockingStreamingHttpResponse
representation of thisStreamingHttpResponse
.
-
version
StreamingHttpResponse version(HttpProtocolVersion version)
Description copied from interface:HttpMetaData
Set the protocol version of thisHttpMetaData
.- Specified by:
version
in interfaceHttpMetaData
- Specified by:
version
in interfaceHttpResponseMetaData
- Parameters:
version
- the protocol version to set.- Returns:
this
.
-
encoding
StreamingHttpResponse encoding(ContentCodec encoding)
Description copied from interface:HttpMetaData
TheContentCodec
used to encode the payload of a request or a response. If the endpoint is setup withContentCodingHttpServiceFilter
, the server will auto-establish the accepted encoding for the response, unless the caller provides a specific encoding by calling this method. Any encoding passed here, takes precedence. In other words, a compressed response, can be disabled by passingContentCodings.identity()
.- Specified by:
encoding
in interfaceHttpMetaData
- Parameters:
encoding
- TheContentCodec
used for the encoding of the payload.- Returns:
this
.- See Also:
- Content-Encoding
-
addHeader
default StreamingHttpResponse addHeader(java.lang.CharSequence name, java.lang.CharSequence value)
Description copied from interface:HttpMetaData
Adds a new header with the specifiedname
andvalue
.- Specified by:
addHeader
in interfaceHttpMetaData
- Specified by:
addHeader
in interfaceHttpResponseMetaData
- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
addHeaders
default StreamingHttpResponse addHeaders(HttpHeaders headers)
Description copied from interface:HttpMetaData
Adds all header names and values ofheaders
object.- Specified by:
addHeaders
in interfaceHttpMetaData
- Specified by:
addHeaders
in interfaceHttpResponseMetaData
- Parameters:
headers
- the headers to add.- Returns:
this
.
-
setHeader
default StreamingHttpResponse setHeader(java.lang.CharSequence name, java.lang.CharSequence value)
Description copied from interface:HttpMetaData
Sets a header with the specifiedname
andvalue
. Any existing headers with the same name are overwritten.- Specified by:
setHeader
in interfaceHttpMetaData
- Specified by:
setHeader
in interfaceHttpResponseMetaData
- Parameters:
name
- the name of the header.value
- the value of the header.- Returns:
this
.
-
setHeaders
default StreamingHttpResponse setHeaders(HttpHeaders headers)
Description copied from interface:HttpMetaData
Clears the current header entries and copies all header entries of the specifiedheaders
object.- Specified by:
setHeaders
in interfaceHttpMetaData
- Specified by:
setHeaders
in interfaceHttpResponseMetaData
- Parameters:
headers
- the headers object which contains new values.- Returns:
this
.
-
addCookie
default StreamingHttpResponse addCookie(HttpCookiePair cookie)
Description copied from interface:HttpMetaData
Adds a cookie.This may result in multiple
HttpCookiePair
s with same name.- Specified by:
addCookie
in interfaceHttpMetaData
- Specified by:
addCookie
in interfaceHttpResponseMetaData
- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addCookie
default StreamingHttpResponse addCookie(java.lang.CharSequence name, java.lang.CharSequence value)
Description copied from interface:HttpMetaData
Adds a cookie with the specifiedname
andvalue
.This may result in multiple
HttpSetCookie
s with same name. Added cookie will not be wrapped, not secure, and not HTTP-only, with no path, domain, expire date and maximum age.- Specified by:
addCookie
in interfaceHttpMetaData
- Specified by:
addCookie
in interfaceHttpResponseMetaData
- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
this
.
-
addSetCookie
default StreamingHttpResponse addSetCookie(HttpSetCookie cookie)
Description copied from interface:HttpMetaData
Adds a set-cookie.This may result in multiple
HttpSetCookie
s with same name.- Specified by:
addSetCookie
in interfaceHttpMetaData
- Specified by:
addSetCookie
in interfaceHttpResponseMetaData
- Parameters:
cookie
- the cookie to add.- Returns:
this
.
-
addSetCookie
default StreamingHttpResponse addSetCookie(java.lang.CharSequence name, java.lang.CharSequence value)
Description copied from interface:HttpMetaData
Adds a set-cookie with the specifiedname
andvalue
.This may result in multiple
HttpSetCookie
s with same name. Added cookie will not be wrapped, not secure, and not HTTP-only, with no path, domain, expire date and maximum age.- Specified by:
addSetCookie
in interfaceHttpMetaData
- Specified by:
addSetCookie
in interfaceHttpResponseMetaData
- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
this
.
-
-