public interface AsyncResponse
!Note: This response is not designed as thread-safe, but it does a special committing control that only one thread is
allowed to commit this response, which means you can not commit this response by calling sendResult(int)
method if another thread had committed this response(such as using the outputStream() to write data).
| 限定符和类型 | 接口和说明 |
|---|---|
static interface |
AsyncResponse.EndListener
已过时。
|
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
Default buffer size of output stream.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addCookie(io.netty.handler.codec.http.cookie.Cookie cookie)
Adds the specified cookie to the response.
|
void |
addCookie(String name,
String value)
Adds the specified cookie to the response.
|
default void |
addEndListener(AsyncResponse.EndListener endListener)
已过时。
use
onEnd(Consumer) |
void |
addHeader(CharSequence name,
String value)
Adds a response header with the given name and value.
|
default void |
addHeader(String name,
String value) |
void |
addIntHeader(CharSequence name,
int value)
Adds a response header with the given name and integer value.
|
default void |
addIntHeader(String name,
int value) |
void |
addShortHeader(CharSequence name,
short value)
Adds a response header with the given name and short value.
|
default void |
addShortHeader(String name,
short value) |
void |
addTrailer(CharSequence name,
String value)
Adds a trailing header with the given name and value.
|
default void |
addTrailer(String name,
String value) |
io.netty.buffer.ByteBufAllocator |
alloc()
Get current ByteBufAllocator
|
int |
bufferSize()
Get the buffer size of the output stream.
|
boolean |
containsHeader(CharSequence name)
Returns a boolean indicating whether the named response header has already been set.
|
default boolean |
containsHeader(String name) |
default int |
getBufferSize()
已过时。
use
bufferSize() |
String |
getHeader(CharSequence name)
Return the value for the specified header, or
null if this header has not been set. |
default String |
getHeader(String name)
Return the value for the specified header, or
null if this header has not been set. |
default Collection<String> |
getHeaderNames()
已过时。
use
headerNames() |
Collection<String> |
getHeaders(CharSequence name)
Return a Collection of all the header values associated with the specified header name.
|
default Collection<String> |
getHeaders(String name) |
default HttpOutputStream |
getOutputStream()
已过时。
use
outputStream() |
default int |
getStatus()
已过时。
use
status() |
Collection<String> |
headerNames()
Get the header names set for this HTTP response.
|
boolean |
isCommitted()
Is current response has been write.
|
boolean |
isKeepAlive()
Is current request should be keepAlive mode.
|
void |
onEnd(Consumer<AsyncResponse> listener)
Add a listener to this response, this listener will be called after current response has been write.
|
HttpOutputStream |
outputStream()
Get output stream of this response.
|
void |
reset()
Reset this response to origin status, which means the values you have changed will be reset such headers, status
and so on.
|
default void |
sendFile(File file) |
default void |
sendFile(File file,
long offset) |
void |
sendFile(File file,
long offset,
long length)
Sends a file to client.
|
default void |
sendRedirect(String newUri)
Sends a temporary redirect response to the client using the given redirect uri.
|
default void |
sendResult()
This method does not modify
readerIndex or writerIndex of this buffer. |
default void |
sendResult(byte[] body)
write response
|
void |
sendResult(byte[] body,
int off,
int len)
Write the byte data.
|
default void |
sendResult(io.netty.buffer.ByteBuf body)
This method does not modify
readerIndex or writerIndex of this buffer. |
default void |
sendResult(io.netty.buffer.ByteBuf body,
boolean autoRelease)
This method does not modify
readerIndex or writerIndex of this buffer. |
default void |
sendResult(io.netty.buffer.ByteBuf body,
int off,
int len) |
void |
sendResult(io.netty.buffer.ByteBuf body,
int off,
int len,
boolean autoRelease) |
default void |
sendResult(int code)
This method does not modify
readerIndex or writerIndex of this buffer. |
default void |
sendResult(int code,
byte[] body) |
default void |
sendResult(int code,
byte[] body,
int off,
int len) |
default void |
sendResult(int code,
io.netty.buffer.ByteBuf body)
This method does not modify
readerIndex or writerIndex of this buffer. |
default void |
sendResult(int code,
io.netty.buffer.ByteBuf body,
boolean autoRelease)
This method does not modify
readerIndex or writerIndex of this buffer. |
default void |
sendResult(int code,
io.netty.buffer.ByteBuf body,
int off,
int len) |
default void |
sendResult(int code,
io.netty.buffer.ByteBuf body,
int off,
int len,
boolean autoRelease)
Write the ByteBuf data.
|
void |
setBufferSize(int size)
Set buffer size of the output stream. it will not be effective unless current output stream is null, which means
you'd better call this function before
outputStream()
advice: always set the buffer size if you have already known the length or the predication of the response data. |
void |
setHeader(CharSequence name,
String value)
Sets a response header with the given name and value.
|
default void |
setHeader(String name,
String value) |
void |
setHeaders(CharSequence name,
List<String> values)
Sets a response headers with the given name and value.
|
default void |
setHeaders(String name,
List<String> values)
Sets a response headers with the given name and value.
|
void |
setIntHeader(CharSequence name,
int value)
Sets a response header with the given name and integer value.
|
default void |
setIntHeader(String name,
int value) |
void |
setShortHeader(CharSequence name,
short value)
Sets a response header with the given name and short value.
|
default void |
setShortHeader(String name,
short value) |
void |
setStatus(int code)
Set the response code
|
void |
setTrailer(CharSequence name,
String value)
Sets a trailing header with the given name and value.
|
default void |
setTrailer(String name,
String value) |
void |
setTrailers(CharSequence name,
List<String> values)
Sets a trailing headers with the given name and value.
|
default void |
setTrailers(String name,
List<String> values) |
int |
status()
Get current http response code.
|
static final int DEFAULT_BUFFER_SIZE
void setStatus(int code)
code - codeint status()
boolean isKeepAlive()
HttpOutputStream outputStream()
null
Note: Once you have called this function you should use this output stream to write your response data rather than using other method such as sendResult(...)
void setBufferSize(int size)
outputStream()
advice: always set the buffer size if you have already known the length or the predication of the response data.
size - sizeint bufferSize()
boolean isCommitted()
void reset()
void sendResult(byte[] body,
int off,
int len)
Note: Once you have called this function you should use this method call to write your response data rather than
using other method such as outputStream() sendResult(...)}
this function can be called only once. This method does not modify readerIndex or writerIndex of
this buffer.
body - byte dataoff - offlen - lenIllegalStateException - if response has committeddefault void sendResult(int code,
byte[] body,
int off,
int len)
IllegalStateException - if response has committedsendResult(byte[], int, int)default void sendResult(byte[] body)
default void sendResult(int code,
byte[] body)
default void sendResult(int code)
readerIndex or writerIndex of this buffer.code - codesendResult(int, byte[], int, int)default void sendResult()
readerIndex or writerIndex of this buffer.void sendResult(io.netty.buffer.ByteBuf body,
int off,
int len,
boolean autoRelease)
default void sendResult(int code,
io.netty.buffer.ByteBuf body,
int off,
int len,
boolean autoRelease)
Note: Once you have called this function you should use this method call to write your response data rather than
using other method such as outputStream() sendResult(...)}
this function can be called only once. This method does not modify readerIndex or writerIndex of
this buffer.
code - codebody - byte dataoff - offlen - lenautoRelease - is automatically release this body ByteBuf even though this method call is retuning with a
ExceptionIllegalStateException - if response has committeddefault void sendResult(int code,
io.netty.buffer.ByteBuf body,
int off,
int len)
default void sendResult(io.netty.buffer.ByteBuf body,
int off,
int len)
default void sendResult(io.netty.buffer.ByteBuf body,
boolean autoRelease)
readerIndex or writerIndex of this buffer.body - bodysendResult(int, ByteBuf, int, int)default void sendResult(int code,
io.netty.buffer.ByteBuf body,
boolean autoRelease)
readerIndex or writerIndex of this buffer.code - codebody - bodysendResult(int, ByteBuf, int, int)default void sendResult(int code,
io.netty.buffer.ByteBuf body)
readerIndex or writerIndex of this buffer.code - codebody - bodysendResult(int, ByteBuf, int, int)default void sendResult(io.netty.buffer.ByteBuf body)
readerIndex or writerIndex of this buffer.body - bodysendResult(int, ByteBuf, int, int)default void sendRedirect(String newUri)
If the new url is relative without a leading '/' it will be regarded as a relative path to the current request URI. otherwise it will be regarded as a relative path to root path.
newUri - target uridefault void sendFile(File file)
default void sendFile(File file, long offset)
void sendFile(File file, long offset, long length)
Note that this is an asynchronous method but we do not provides any promise or callback for user.
file - target file to send.offset - start index to sendlength - length.@Beta io.netty.buffer.ByteBufAllocator alloc()
default String getHeader(String name)
null if this header has not been set. If more than one
value was added for this name, only the first is returned; use getHeaders(String) to retrieve all of
them.name - healder nameString getHeader(CharSequence name)
null if this header has not been set. If more than one
value was added for this name, only the first is returned; use getHeaders(String) to retrieve all of
them.name - healder nameCollection<String> headerNames()
Collection<String> getHeaders(CharSequence name)
name - header namedefault Collection<String> getHeaders(String name)
getHeaders(CharSequence)boolean containsHeader(CharSequence name)
name - namedefault boolean containsHeader(String name)
void addHeader(CharSequence name, String value)
name - header namevalue - valuevoid setHeader(CharSequence name, String value)
name - namevalue - valuevoid setHeaders(CharSequence name, List<String> values)
name - namevalues - valuesdefault void setHeaders(String name, List<String> values)
name - namevalues - valuesvoid setIntHeader(CharSequence name, int value)
name - namevalue - valuedefault void setIntHeader(String name, int value)
void addIntHeader(CharSequence name, int value)
name - namevalue - valuedefault void addIntHeader(String name, int value)
void setShortHeader(CharSequence name, short value)
name - namevalue - valuedefault void setShortHeader(String name, short value)
void addShortHeader(CharSequence name, short value)
name - namevalue - valuedefault void addShortHeader(String name, short value)
void addTrailer(CharSequence name, String value)
name - namevalue - valuevoid setTrailer(CharSequence name, String value)
name - namevalue - valuevoid setTrailers(CharSequence name, List<String> values)
name - namevalues - valuesvoid addCookie(io.netty.handler.codec.http.cookie.Cookie cookie)
cookie - the Cookie to return to the clientvoid addCookie(String name, String value)
name - cookie namevalue - valuevoid onEnd(Consumer<AsyncResponse> listener)
listener - listener@Deprecated default void addEndListener(AsyncResponse.EndListener endListener)
onEnd(Consumer)endListener - listener@Deprecated default int getStatus()
status()@Deprecated default HttpOutputStream getOutputStream()
outputStream()@Deprecated default int getBufferSize()
bufferSize()@Deprecated default Collection<String> getHeaderNames()
headerNames()Copyright © 2020. All rights reserved.