public class MockServerHttpResponse extends AbstractServerHttpResponse
AbstractServerHttpResponse
for use in tests without
an actual server.
By default response content is consumed in full upon writing and cached
for subsequent access, however it is also possible to set a custom
writeHandler
.
Constructor and Description |
---|
MockServerHttpResponse() |
Modifier and Type | Method and Description |
---|---|
protected void |
applyCookies()
Add cookies from
AbstractServerHttpResponse.getHeaders() to the underlying response. |
protected void |
applyHeaders()
Apply header changes from
AbstractServerHttpResponse.getHeaders() to the underlying response. |
protected void |
applyStatusCode()
Write the status code to the underlying response.
|
reactor.core.publisher.Flux<DataBuffer> |
getBody()
Return the response body or an error stream if the body was not set.
|
reactor.core.publisher.Mono<java.lang.String> |
getBodyAsString()
Aggregate response data and convert to a String using the "Content-Type"
charset or "UTF-8" by default.
|
<T> T |
getNativeResponse()
Return the underlying server response.
|
reactor.core.publisher.Mono<java.lang.Void> |
setComplete()
Indicate that message handling is complete, allowing for any cleanup or
end-of-processing tasks to be performed such as applying header changes
made via
HttpMessage.getHeaders() to the underlying HTTP message (if not
applied already). |
void |
setWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<java.lang.Void>> writeHandler)
Configure a custom handler to consume the response body.
|
protected reactor.core.publisher.Mono<java.lang.Void> |
writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Write to the underlying the response, and flush after each
Publisher<DataBuffer> . |
protected reactor.core.publisher.Mono<java.lang.Void> |
writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
Write to the underlying the response.
|
addCookie, beforeCommit, bufferFactory, doCommit, doCommit, getCookies, getHeaders, getStatusCode, getStatusCodeValue, isCommitted, setStatusCode, setStatusCodeValue, writeAndFlushWith, writeWith
public void setWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<java.lang.Void>> writeHandler)
By default, response body content is consumed in full and cached for subsequent access in tests. Use this option to take control over how the response body is consumed.
writeHandler
- the write handler to use returning Mono<Void>
when the body has been "written" (i.e. consumed).public <T> T getNativeResponse()
AbstractServerHttpResponse
Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
getNativeResponse
in class AbstractServerHttpResponse
protected void applyStatusCode()
AbstractServerHttpResponse
applyStatusCode
in class AbstractServerHttpResponse
protected void applyHeaders()
AbstractServerHttpResponse
AbstractServerHttpResponse.getHeaders()
to the underlying response.
This method is called once only.applyHeaders
in class AbstractServerHttpResponse
protected void applyCookies()
AbstractServerHttpResponse
AbstractServerHttpResponse.getHeaders()
to the underlying response.
This method is called once only.applyCookies
in class AbstractServerHttpResponse
protected reactor.core.publisher.Mono<java.lang.Void> writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
AbstractServerHttpResponse
writeWithInternal
in class AbstractServerHttpResponse
body
- the publisher to write withprotected reactor.core.publisher.Mono<java.lang.Void> writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
AbstractServerHttpResponse
Publisher<DataBuffer>
.writeAndFlushWithInternal
in class AbstractServerHttpResponse
body
- the publisher to write and flush withpublic reactor.core.publisher.Mono<java.lang.Void> setComplete()
ReactiveHttpOutputMessage
HttpMessage.getHeaders()
to the underlying HTTP message (if not
applied already).
This method should be automatically invoked at the end of message processing so typically applications should not have to invoke it. If invoked multiple times it should have no side effects.
setComplete
in interface ReactiveHttpOutputMessage
setComplete
in class AbstractServerHttpResponse
Mono
that indicates completion or errorpublic reactor.core.publisher.Flux<DataBuffer> getBody()
public reactor.core.publisher.Mono<java.lang.String> getBodyAsString()