public interface HttpResponse
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(Cookie cookie)
添加Cookie信息
|
void |
addHeader(String name,
String value)
Adds a response header with the given name and value.
|
void |
close() |
long |
getContentLength() |
String |
getContentType() |
String |
getHeader(String name) |
Collection<String> |
getHeaderNames()
Get the header names set for this HTTP response.
|
Collection<String> |
getHeaders(String name)
Return a Collection of all the header values associated with the
specified header name.
|
HttpStatus |
getHttpStatus()
获取Http响应状态
|
BufferOutputStream |
getOutputStream()
响应消息输出流
|
default Supplier<Map<String,String>> |
getTrailerFields()
Gets the supplier of trailer headers.
|
void |
setContentLength(long contentLength) |
void |
setContentType(String contentType) |
void |
setHeader(String name,
String value)
Sets a response header with the given name and value.
|
void |
setHttpStatus(HttpStatus httpStatus)
设置Http响应状态,若不设置默认
HttpStatus.OK |
void |
setHttpStatus(int httpStatus,
String reasonPhrase)
设置Http响应状态,若不设置默认
HttpStatus.OK |
default void |
setTrailerFields(Supplier<Map<String,String>> supplier)
Sets the supplier of trailer headers.
|
void |
write(byte[] data) |
BufferOutputStream getOutputStream()
HttpStatus getHttpStatus()
void setHttpStatus(HttpStatus httpStatus)
HttpStatus.OKhttpStatus - void setHttpStatus(int httpStatus,
String reasonPhrase)
HttpStatus.OKhttpStatus - void setHeader(String name, String value)
containsHeader method can be used to test for the presence
of a header before setting its value.name - the name of the headervalue - the header value If it contains octet string, it should be
encoded according to RFC 2047
(http://www.ietf.org/rfc/rfc2047.txt)addHeader(java.lang.String, java.lang.String)void addHeader(String name, String value)
name - the name of the headervalue - the additional header value If it contains octet string, it
should be encoded according to RFC 2047
(http://www.ietf.org/rfc/rfc2047.txt)setHeader(java.lang.String, java.lang.String)Collection<String> getHeaders(String name)
name - Header name to look upCollection<String> getHeaderNames()
void setContentLength(long contentLength)
long getContentLength()
void setContentType(String contentType)
String getContentType()
void write(byte[] data)
throws IOException
IOExceptionvoid close()
void addCookie(Cookie cookie)
cookie - default void setTrailerFields(Supplier<Map<String,String>> supplier)
The trailer header field value is defined as a comma-separated list (see Section 3.2.2 and Section 4.1.2 of RFC 7230).
The supplier will be called within the scope of whatever thread/call causes the response content to be completed. Typically this will be any thread calling close() on the output stream or writer.
The trailers that run afoul of the provisions of section 4.1.2 of RFC 7230 are ignored.
The RFC requires the name of every key that is to be in the supplied Map is included in the comma separated list that is the value of the "Trailer" response header. The application is responsible for ensuring this requirement is met. Failure to do so may lead to interoperability failures.
supplier - the supplier of trailer headersIllegalStateException - if it is invoked after the response has has been committed, or the trailer is not
supported in the request, for instance, the underlying protocol is HTTP 1.0, or the response is not in chunked
encoding in HTTP 1.1.Copyright © 2025. All rights reserved.