@Internal public class AsyncResponseImpl extends Object implements AsyncResponse
AsyncResponse that wraps the Response as delegate.AsyncResponse.EndListenerDEFAULT_BUFFER_SIZE| 构造器和说明 |
|---|
AsyncResponseImpl(esa.httpserver.core.Response res) |
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
void |
addHeader(CharSequence name,
String value)
Adds a response header with the given name and value.
|
void |
addIntHeader(CharSequence name,
int value)
Adds a response header with the given name and integer value.
|
void |
addShortHeader(CharSequence name,
short value)
Adds a response header with the given name and short value.
|
void |
addTrailer(CharSequence name,
String value)
Adds a trailing header with the given name and 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.
|
String |
getHeader(CharSequence name)
Return the value for the specified header, or
null if this header has not been set. |
Collection<String> |
getHeaders(CharSequence name)
Return a Collection of all the header values associated with the specified header name.
|
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.
|
void |
sendFile(File file,
long offset,
long length)
Sends a file to client.
|
void |
sendRedirect(String newUri)
Sends a temporary redirect response to the client using the given redirect uri.
|
void |
sendResult(byte[] body)
write response
|
void |
sendResult(byte[] body,
int off,
int len)
Write the byte data.
|
void |
sendResult(io.netty.buffer.ByteBuf body,
boolean autoRelease)
This method does not modify
readerIndex or writerIndex of this buffer. |
void |
sendResult(io.netty.buffer.ByteBuf body,
int off,
int len,
boolean autoRelease) |
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
AsyncResponse.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.
|
void |
setHeaders(CharSequence 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.
|
void |
setShortHeader(CharSequence name,
short value)
Sets a response header with the given name and 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.
|
void |
setTrailers(CharSequence name,
List<String> values)
Sets a trailing headers with the given name and value.
|
int |
status()
Get current http response code.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddEndListener, addHeader, addIntHeader, addShortHeader, addTrailer, containsHeader, getBufferSize, getHeader, getHeaderNames, getHeaders, getOutputStream, getStatus, sendFile, sendFile, sendResult, sendResult, sendResult, sendResult, sendResult, sendResult, sendResult, sendResult, sendResult, sendResult, setHeader, setHeaders, setIntHeader, setShortHeader, setTrailer, setTrailerspublic void setStatus(int code)
AsyncResponsesetStatus 在接口中 AsyncResponsecode - codepublic int status()
AsyncResponsestatus 在接口中 AsyncResponsepublic boolean isKeepAlive()
AsyncResponseisKeepAlive 在接口中 AsyncResponsepublic HttpOutputStream outputStream()
AsyncResponsenull
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(...)
outputStream 在接口中 AsyncResponsepublic void setBufferSize(int size)
AsyncResponseAsyncResponse.outputStream()
advice: always set the buffer size if you have already known the length or the predication of the response data.
setBufferSize 在接口中 AsyncResponsesize - sizepublic int bufferSize()
AsyncResponsebufferSize 在接口中 AsyncResponsepublic boolean isCommitted()
AsyncResponseisCommitted 在接口中 AsyncResponsepublic void reset()
AsyncResponsereset 在接口中 AsyncResponsepublic void sendResult(byte[] body,
int off,
int len)
AsyncResponse
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 AsyncResponse.outputStream() sendResult(...)}
this function can be called only once. This method does not modify readerIndex or writerIndex of
this buffer.
sendResult 在接口中 AsyncResponsebody - byte dataoff - offlen - lenpublic void sendResult(byte[] body)
AsyncResponsesendResult 在接口中 AsyncResponseAsyncResponse.sendResult(int, byte[], int, int)public void sendResult(io.netty.buffer.ByteBuf body,
boolean autoRelease)
AsyncResponsereaderIndex or writerIndex of this buffer.sendResult 在接口中 AsyncResponsebody - bodyAsyncResponse.sendResult(int, ByteBuf, int, int)public void sendResult(io.netty.buffer.ByteBuf body,
int off,
int len,
boolean autoRelease)
public void sendFile(File file, long offset, long length)
AsyncResponseNote that this is an asynchronous method but we do not provides any promise or callback for user.
sendFile 在接口中 AsyncResponsefile - target file to send.offset - start index to sendlength - length.public void sendRedirect(String newUri)
AsyncResponseIf 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.
sendRedirect 在接口中 AsyncResponsenewUri - target uripublic io.netty.buffer.ByteBufAllocator alloc()
AsyncResponsealloc 在接口中 AsyncResponsepublic String getHeader(CharSequence name)
AsyncResponsenull if this header has not been set. If more than one
value was added for this name, only the first is returned; use AsyncResponse.getHeaders(String) to retrieve all of
them.getHeader 在接口中 AsyncResponsename - healder namepublic Collection<String> headerNames()
AsyncResponseheaderNames 在接口中 AsyncResponsepublic Collection<String> getHeaders(CharSequence name)
AsyncResponsegetHeaders 在接口中 AsyncResponsename - header namepublic boolean containsHeader(CharSequence name)
AsyncResponsecontainsHeader 在接口中 AsyncResponsename - namepublic void addHeader(CharSequence name, String value)
AsyncResponseaddHeader 在接口中 AsyncResponsename - header namevalue - valuepublic void setHeader(CharSequence name, String value)
AsyncResponsesetHeader 在接口中 AsyncResponsename - namevalue - valuepublic void setHeaders(CharSequence name, List<String> values)
AsyncResponsesetHeaders 在接口中 AsyncResponsename - namevalues - valuespublic void setIntHeader(CharSequence name, int value)
AsyncResponsesetIntHeader 在接口中 AsyncResponsename - namevalue - valuepublic void addIntHeader(CharSequence name, int value)
AsyncResponseaddIntHeader 在接口中 AsyncResponsename - namevalue - valuepublic void setShortHeader(CharSequence name, short value)
AsyncResponsesetShortHeader 在接口中 AsyncResponsename - namevalue - valuepublic void addShortHeader(CharSequence name, short value)
AsyncResponseaddShortHeader 在接口中 AsyncResponsename - namevalue - valuepublic void addTrailer(CharSequence name, String value)
AsyncResponseaddTrailer 在接口中 AsyncResponsename - namevalue - valuepublic void setTrailer(CharSequence name, String value)
AsyncResponsesetTrailer 在接口中 AsyncResponsename - namevalue - valuepublic void setTrailers(CharSequence name, List<String> values)
AsyncResponsesetTrailers 在接口中 AsyncResponsename - namevalues - valuespublic void addCookie(io.netty.handler.codec.http.cookie.Cookie cookie)
AsyncResponseaddCookie 在接口中 AsyncResponsecookie - the Cookie to return to the clientpublic void addCookie(String name, String value)
AsyncResponseaddCookie 在接口中 AsyncResponsename - cookie namevalue - valuepublic void onEnd(Consumer<AsyncResponse> listener)
AsyncResponseonEnd 在接口中 AsyncResponselistener - listenerCopyright © 2020. All rights reserved.