Class ServletServerHttpResponse
java.lang.Object
org.springframework.http.server.ServletServerHttpResponse
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, HttpMessage, HttpOutputMessage, ServerHttpResponse
ServerHttpResponse implementation that is based on a HttpServletResponse.- Since:
- 3.0
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Brian Clozel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSystem property that indicates whetherresponse.getBody().flush()should effectively flush to the network. -
Constructor Summary
ConstructorsConstructorDescriptionServletServerHttpResponse(jakarta.servlet.http.HttpServletResponse servletResponse) Construct a new instance of the ServletServerHttpResponse based on the givenHttpServletResponse. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this response, freeing any resources created.voidflush()Ensure that the headers and the content of the response are written out.getBody()Return the body of the message as an output stream.Return the headers of this message.jakarta.servlet.http.HttpServletResponseReturn theHttpServletResponsethis object is based on.voidsetStatusCode(HttpStatusCode status) Set the HTTP status code of the response.
-
Field Details
-
FLUSH_ENABLED_PROPERTY_NAME
System property that indicates whetherresponse.getBody().flush()should effectively flush to the network. This is by default disabled, and developers must set the "spring.http.response.flush.enabled" Spring property to turn it on.Applications should instead
flush()on the response directly.- Since:
- 7.0.6
- See Also:
-
-
Constructor Details
-
ServletServerHttpResponse
public ServletServerHttpResponse(jakarta.servlet.http.HttpServletResponse servletResponse) Construct a new instance of the ServletServerHttpResponse based on the givenHttpServletResponse.- Parameters:
servletResponse- the servlet response
-
-
Method Details
-
getServletResponse
public jakarta.servlet.http.HttpServletResponse getServletResponse()Return theHttpServletResponsethis object is based on. -
setStatusCode
Description copied from interface:ServerHttpResponseSet the HTTP status code of the response.- Specified by:
setStatusCodein interfaceServerHttpResponse- Parameters:
status- the HTTP status as an HttpStatus enum value
-
getHeaders
Description copied from interface:HttpMessageReturn the headers of this message.- Specified by:
getHeadersin interfaceHttpMessage- Returns:
- a corresponding HttpHeaders object (never
null)
-
getBody
Return the body of the message as an output stream.By default, flushing the output stream has no effect (see
FLUSH_ENABLED_PROPERTY_NAME) and should be performed using the ServerHttpResponse-levelflush()method instead.- Specified by:
getBodyin interfaceHttpOutputMessage- Returns:
- the output stream body (never
null) - Throws:
IOException- in case of I/O errors
-
flush
Description copied from interface:ServerHttpResponseEnsure that the headers and the content of the response are written out.After the first flush, headers can no longer be changed. Only further content writing and content flushing is possible.
- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfaceServerHttpResponse- Throws:
IOException
-
close
public void close()Description copied from interface:ServerHttpResponseClose this response, freeing any resources created.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceServerHttpResponse
-