public abstract class AbstractServerHttpResponse extends Object implements ServerHttpResponse
ServerHttpResponse implementations.| Constructor and Description |
|---|
AbstractServerHttpResponse(org.springframework.core.io.buffer.DataBufferFactory dataBufferFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
applyCookies()
Implement this method to add cookies from
getHeaders() to the
underlying response. |
protected abstract void |
applyHeaders()
Implement this method to apply header changes from
getHeaders()
to the underlying response. |
protected abstract void |
applyStatusCode()
Implement this method to write the status code to the underlying response.
|
void |
beforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action)
Register an action to be applied just before the message is committed.
|
org.springframework.core.io.buffer.DataBufferFactory |
bufferFactory()
Return a
DataBufferFactory that can be used for creating the body. |
protected reactor.core.publisher.Mono<Void> |
doCommit()
A variant of
doCommit(Supplier) for a response without no body. |
protected reactor.core.publisher.Mono<Void> |
doCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> writeAction)
Apply
beforeCommit actions, apply the
response status and headers/cookies, and write the response body. |
String |
encodeUrl(String url)
A mechanism for URL rewriting that applications and libraries such as
HTML template libraries to use consistently for all URLs emitted by
the application.
|
org.springframework.util.MultiValueMap<String,ResponseCookie> |
getCookies()
Return a mutable map with the cookies to send to the server.
|
HttpHeaders |
getHeaders()
Return the headers of this message.
|
HttpStatus |
getStatusCode()
Return the HTTP status code or
null if not set. |
void |
registerUrlEncoder(Function<String,String> encoder)
Register a URL rewriting function for use with
ServerHttpResponse.encodeUrl(java.lang.String). |
reactor.core.publisher.Mono<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). |
boolean |
setStatusCode(HttpStatus statusCode)
Set the HTTP status code of the response.
|
reactor.core.publisher.Mono<Void> |
writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)
Use the given
Publisher of Publishers to write the body of the
message to the underlying HTTP layer, flushing after each
Publisher<DataBuffer>. |
protected abstract reactor.core.publisher.Mono<Void> |
writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)
Implement this method to write to the underlying the response, and flush after
each
Publisher<DataBuffer>. |
reactor.core.publisher.Mono<Void> |
writeWith(org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)
Use the given
Publisher to write the body of the message to the underlying
HTTP layer. |
protected abstract reactor.core.publisher.Mono<Void> |
writeWithInternal(org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)
Implement this method to write to the underlying the response.
|
public AbstractServerHttpResponse(org.springframework.core.io.buffer.DataBufferFactory dataBufferFactory)
public final org.springframework.core.io.buffer.DataBufferFactory bufferFactory()
ReactiveHttpOutputMessageDataBufferFactory that can be used for creating the body.bufferFactory in interface ReactiveHttpOutputMessageReactiveHttpOutputMessage.writeWith(Publisher)public boolean setStatusCode(HttpStatus statusCode)
ServerHttpResponsesetStatusCode in interface ServerHttpResponsestatusCode - the HTTP status as an HttpStatus enum valuefalse if the status code has not been set because the HTTP response
is already committed, true if it has been set correctly.public HttpStatus getStatusCode()
ServerHttpResponsenull if not set.getStatusCode in interface ServerHttpResponsepublic HttpHeaders getHeaders()
HttpMessagegetHeaders in interface HttpMessagenull)public org.springframework.util.MultiValueMap<String,ResponseCookie> getCookies()
ServerHttpResponsegetCookies in interface ServerHttpResponsepublic String encodeUrl(String url)
ServerHttpResponseServerHttpResponse.registerUrlEncoder(java.util.function.Function<java.lang.String, java.lang.String>) that can insert an id for authentication,
a nonce for CSRF protection, a version for a static resource, etc.encodeUrl in interface ServerHttpResponseurl - the URL to encodepublic void registerUrlEncoder(Function<String,String> encoder)
ServerHttpResponseServerHttpResponse.encodeUrl(java.lang.String).
The function must return an encoded URL or the same URL.registerUrlEncoder in interface ServerHttpResponseencoder - a URL encoding function to usepublic void beforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action)
ReactiveHttpOutputMessagebeforeCommit in interface ReactiveHttpOutputMessageaction - the actionpublic final reactor.core.publisher.Mono<Void> writeWith(org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)
ReactiveHttpOutputMessagePublisher to write the body of the message to the underlying
HTTP layer.writeWith in interface ReactiveHttpOutputMessagebody - the body content publisherMono that indicates completion or errorpublic final reactor.core.publisher.Mono<Void> writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)
ReactiveHttpOutputMessagePublisher of Publishers to write the body of the
message to the underlying HTTP layer, flushing after each
Publisher<DataBuffer>.writeAndFlushWith in interface ReactiveHttpOutputMessagebody - the body content publisherMono that indicates completion or errorpublic reactor.core.publisher.Mono<Void> setComplete()
ReactiveHttpOutputMessageHttpMessage.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 ReactiveHttpOutputMessageMono that indicates completion or errorprotected reactor.core.publisher.Mono<Void> doCommit()
doCommit(Supplier) for a response without no body.protected reactor.core.publisher.Mono<Void> doCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> writeAction)
beforeCommit actions, apply the
response status and headers/cookies, and write the response body.writeAction - the action to write the response body or nullprotected abstract reactor.core.publisher.Mono<Void> writeWithInternal(org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)
body - the publisher to write withprotected abstract reactor.core.publisher.Mono<Void> writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)
Publisher<DataBuffer>.body - the publisher to write and flush withprotected abstract void applyStatusCode()
protected abstract void applyHeaders()
getHeaders()
to the underlying response. This method is called once only.protected abstract void applyCookies()
getHeaders() to the
underlying response. This method is called once only.