Class NettyWebResponse
java.lang.Object
services.moleculer.web.netty.NettyWebResponse
- All Implemented Interfaces:
HttpConstants, WebResponse
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.netty.channel.Channelprotected intprotected final io.netty.channel.ChannelHandlerContextprotected AtomicBooleanCustom properties (for inter-middleware communication).protected final NettyWebRequestFields inherited from interface HttpConstants
ACCEPT, ACCEPT_ENCODING, AUTHORIZATION, CACHE_CONTROL, CHUNKED, CLOSE, CONNECT, CONNECTION, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, CONTENT_TYPE_HTML, CONTENT_TYPE_JSON, COOKIE, DEFLATE, DELETE, ETAG, GET, GZIP, HEAD, IF_NONE_MATCH, KEEP_ALIVE, LOCATION, META_CONTENT_TYPE, META_HEADERS, META_LOCALE, META_LOCATION, META_SESSION, META_STATUS, META_TEMPLATE, NO_CACHE, OPTIONS, PATCH, POST, PROPERTY_COOKIES, PROPERTY_SESSION_ID, PROPERTY_USER, PUT, SET_COOKIE, TRACE, TRANSFER_ENCODING, WWW_AUTHENTICATE, X_FORWARDED_FOR -
Constructor Summary
ConstructorsConstructorDescriptionNettyWebResponse(io.netty.channel.ChannelHandlerContext ctx, NettyWebRequest req) -
Method Summary
Modifier and TypeMethodDescriptionbooleanend()Completes the asynchronous operation that was started on the request.Returns the value of the specified response header as a String.Returns the internal object of this WebResponse.getProperty(String name) Returns the value to which the specified "name" is mapped, or null if this WebResponse contains no mapping for the "name".intGets the current status code of this response.voidsend(byte[] bytes) Writes b.length bytes of body from the specified byte array to the output stream.protected voidvoidSets a response header with the given name and value.voidsetProperty(String name, Object value) Associates the specified value with the specified "name" in this WebResponse.voidsetStatus(int code) Sets the status code for this response.
-
Field Details
-
ctx
protected final io.netty.channel.ChannelHandlerContext ctx -
req
-
channel
protected final io.netty.channel.Channel channel -
properties
-
code
protected int code -
headers
-
first
-
-
Constructor Details
-
NettyWebResponse
-
-
Method Details
-
setStatus
public void setStatus(int code) Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the 200 or 404 status codes). This method preserves any cookies and other response headers. Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes are treated as container specific.- Specified by:
setStatusin interfaceWebResponse- Parameters:
code- the status code
-
getStatus
public int getStatus()Gets the current status code of this response.- Specified by:
getStatusin interfaceWebResponse- Returns:
- the status code
-
setHeader
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.- Specified by:
setHeaderin interfaceWebResponse- Parameters:
name- the name of the headervalue- the header value If it contains octet string, it should be encoded according to RFC 2047
-
getHeader
Returns the value of the specified response header as a String. If the response did not include a header of the specified name, this method returns null. If there are multiple headers with the same name, this method returns the first head in the response.- Specified by:
getHeaderin interfaceWebResponse- Parameters:
name- name a String specifying the header name- Returns:
- a String containing the value of the response header, or null if the response does not have a header of that name
-
send
Writes b.length bytes of body from the specified byte array to the output stream.- Specified by:
sendin interfaceWebResponse- Parameters:
bytes- the data- Throws:
IOException- if an I/O error occurs
-
end
public boolean end()Completes the asynchronous operation that was started on the request.- Specified by:
endin interfaceWebResponse- Returns:
- return true, if all resources are released
-
sendHeaders
protected void sendHeaders() -
setProperty
Associates the specified value with the specified "name" in this WebResponse. If the WebResponse previously contained a mapping for the "name", the old value is replaced.- Specified by:
setPropertyin interfaceWebResponse- Parameters:
name- a "name" with which the specified value is to be associatedvalue- value to be associated with the specified "name"
-
getProperty
Returns the value to which the specified "name" is mapped, or null if this WebResponse contains no mapping for the "name".- Specified by:
getPropertyin interfaceWebResponse- Parameters:
name- the "name" whose associated value is to be returned- Returns:
- the value to which the specified "name" is mapped, or null if this WebResponse contains no mapping for the "name"
-
getInternalObject
Returns the internal object of this WebResponse.- Specified by:
getInternalObjectin interfaceWebResponse- Returns:
- internal object (Netty ChannelHandlerContext)
-