public interface Response
!Note: It would be uncompleted state which means current Response haven't been completely written(eg. only
part of the body is written, and waiting to write the left.) and it could be indicated by the return value of isCommitted() isEnded().
Also, you should know that this response is not designed 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 write(byte[]) or end(byte[]) method if another thread had committed this response(such as calling the write(byte[])
method).
| 限定符和类型 | 方法和说明 |
|---|---|
Response |
addCookie(esa.commons.http.Cookie cookie)
Adds the specified cookie to the response.
|
Response |
addCookie(String name,
String value)
Adds the specified cookie to the response.
|
io.netty.buffer.ByteBufAllocator |
alloc()
Get current allocator.
|
default io.netty.util.concurrent.Future<Void> |
end()
Ends current response.
|
default io.netty.util.concurrent.Future<Void> |
end(byte[] data) |
default io.netty.util.concurrent.Future<Void> |
end(byte[] data,
int offset) |
io.netty.util.concurrent.Future<Void> |
end(byte[] data,
int offset,
int length)
Ends current response with writing given
data to the remote. |
io.netty.util.concurrent.Future<Void> |
end(io.netty.buffer.ByteBuf data)
Ends current response with writing given
data to the remote. |
io.netty.util.concurrent.Future<Void> |
endFuture()
Returns the
Future which is notified when the response is ended. |
esa.commons.http.HttpHeaders |
headers()
Returns the headers of this response.
|
boolean |
isCommitted()
Is current response has been write.
|
boolean |
isEnded()
Is current response has been write.
|
boolean |
isKeepAlive()
Whether response will be written as keepalive on current connection or stream(depends on the version of http
protocol)
|
boolean |
isWritable()
Returns whether the extra response data is writable.
|
io.netty.util.concurrent.Future<Void> |
onEndFuture()
Returns the
Future which is notified when the response is about to ending. |
default io.netty.util.concurrent.Future<Void> |
sendFile(File file) |
default io.netty.util.concurrent.Future<Void> |
sendFile(File file,
long offset) |
io.netty.util.concurrent.Future<Void> |
sendFile(File file,
long offset,
long length)
Sends a file to client.
|
default io.netty.util.concurrent.Future<Void> |
sendRedirect(String newUri)
Sends a temporary redirect response to the client using the given redirect uri.
|
Response |
setStatus(int code)
Set the response code
|
int |
status()
Get current http response code.
|
esa.commons.http.HttpHeaders |
trailers()
Returns the trailing headers of this message.
|
default io.netty.util.concurrent.Future<Void> |
write(byte[] data) |
default io.netty.util.concurrent.Future<Void> |
write(byte[] data,
int offset) |
io.netty.util.concurrent.Future<Void> |
write(byte[] data,
int offset,
int length)
Writes some data to the remote.
|
io.netty.util.concurrent.Future<Void> |
write(io.netty.buffer.ByteBuf data)
Writes some data to the remote.
|
int status()
Response setStatus(int code)
code - codeesa.commons.http.HttpHeaders headers()
esa.commons.http.HttpHeaders trailers()
Response addCookie(esa.commons.http.Cookie cookie)
cookie - the Cookie to return to the clientResponse addCookie(String name, String value)
name - cookie namevalue - valueboolean isKeepAlive()
default io.netty.util.concurrent.Future<Void> write(byte[] data)
write(byte[], int, int)default io.netty.util.concurrent.Future<Void> write(byte[] data, int offset)
write(byte[], int, int)io.netty.util.concurrent.Future<Void> write(byte[] data, int offset, int length)
You may need to check the result of isWritable() before writing.
data - data to writeoffset - offsetlength - lengthio.netty.util.concurrent.Future<Void> write(io.netty.buffer.ByteBuf data)
You may need to check the result of isWritable() before writing.
!Note: It is recommended to use this method in current channel event loop, because of the complexity of the
ByteBuf allocation/deallocation
data - data to writedefault io.netty.util.concurrent.Future<Void> end(byte[] data)
end(byte[], int, int)default io.netty.util.concurrent.Future<Void> end(byte[] data, int offset)
end(byte[], int, int)io.netty.util.concurrent.Future<Void> end(byte[] data, int offset, int length)
data to the remote.
You may need to check the result of isWritable() before writing.
data - data to writeoffset - offsetlength - lengthdefault io.netty.util.concurrent.Future<Void> end()
You may need to check the result of isWritable() before writing.
io.netty.util.concurrent.Future<Void> end(io.netty.buffer.ByteBuf data)
data to the remote.
You may need to check the result of isWritable() before writing.
!Note: It is recommended to use this method in current channel event loop, because of the complexity of the
ByteBuf allocation/deallocation
data - data to writedefault io.netty.util.concurrent.Future<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 uriio.netty.util.concurrent.Future<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.boolean isWritable()
true if extra response data is writable, otherwise falseboolean isCommitted()
boolean isEnded()
io.netty.util.concurrent.Future<Void> onEndFuture()
Future which is notified when the response is about to ending.io.netty.util.concurrent.Future<Void> endFuture()
Future which is notified when the response is ended.@Beta io.netty.buffer.ByteBufAllocator alloc()
Copyright © 2020. All rights reserved.